3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Magnus; class ObjectDispatch { public function routeIterator(&$path) { while (!empty($path)) { yield end($path); array_pop($path); /* This prevents having to put back a value in the event of a * readjustment in the dispatch path. * Testing indicates that it's better to do array maninpulation than it is * to implement SplDoublyLinkedList for deque behavior. Likewise, * simply tracking the index is a bit slower and can add complexity * when dealing with reorients/redispatches. */ } } public function __invoke($context, $root) { $log = $context->getLogger(); $path = $context->getRequestPath(); $last = ''; $parent = null; $current = $root; $controllerPrefix = $context->getControllerPrefix(); if ($context->getAppMode() === 'DEBUG' && $log !== null) { $log->addDebug('Starting Object Dispatch', [ 'request' => $context->getRequestURI(), 'path' => var_export($path, true), 'root' => var_export($root, true) ]); } foreach ($this->routeIterator($path) as $chunk) { if ($context->getAppMode() === 'DEBUG' && $log !== null) { $log->addDebug('Beginning dispatch step.', [ 'chunk' => $chunk, 'path' => var_export($path, true), 'current' => var_export($current, true) ]); } if (!is_object($current) || class_exists($controllerPrefix . $current)) { if ($context->getAppMode() === 'DEBUG' && $log !== null) { $log->addDebug('Instantiating current class', [ 'request' => $context->getRequestURI(), 'current' => $current ]); } $resolvedClass = $controllerPrefix . $current; $current = new $resolvedClass($context); } if (is_object($current)) { $parent = $current; } if (in_array($chunk, get_class_methods($parent))) { if ($context->getAppMode() === 'DEBUG' && $log !== null) { $log->addDebug('Found an endpoint', [ 'request' => $context->getRequestURI(), 'isEndpoint' => true, 'parent' => var_export($parent, true), 'handler' => $chunk, 'arguments' => var_export($path, true) ]); } yield array($parent, $chunk, $path, true); } elseif (in_array($chunk, get_object_vars($parent))) { if ($context->getAppMode() === 'DEBUG' && $log !== null) { $log->addDebug('Found a property', [ 'request' => $context->getRequestURI(), 'property' => $chunk, 'parent' => var_export($parent, true) ]); } $current = $parent->chunk; } elseif (method_exists($parent, 'lookup')) { try { list($current, $consumed) = $parent->lookup($path); $chunk = implode('/', $consumed); $path = array_slice($path, 0, count($path) - count($consumed)); } catch (Exception $e) { throw new HTTPNotFound(); } } else { throw new HTTPNotFound(); } yield array(explode('/', $last), $parent, false); $last = $chunk; } if ($context->getAppMode() === 'DEBUG' && $log !== null) { $log->addDebug('No endpoint found', [ 'request' => $context->getRequestURI(), 'current' => var_export($current), 'parent' => var_export($parent) ]); } if (!is_object($current) && class_exists($controllerPrefix . $current)) { $resolvedClass = $controllerPrefix . $current; $current = new $resolvedClass($context); } if (is_callable($current)) { yield array($current, $chunk, $path, true); } elseif (is_callable($parent)) { yield array($parent, $chunk, $path, true); } } } class Context { protected $requestURI; protected $requestPath; protected $appMode; protected $logger; protected $controllerPrefix; public function __construct(Array $config) { $this->requestURI = isset($config['requestURI']) ? $config['requestURI'] : '/'; $this->appMode = isset($config['appMode']) ? $config['appMode'] : 'DEVELOPMENT'; $this->logger = isset($config['logger']) ? $config['logger'] : null; $this->controllerPrefix = isset($config['controllerPrefix']) ? $config['controllerPrefix'] : __NAMESPACE__ . '\\'; $this->requestPath = explode('/', str_replace('\\', '/', $this->requestURI)); if (end($this->requestPath) === '') { array_pop($this->requestPath); } $this->requestPath = array_reverse($this->requestPath); if (end($this->requestPath) === '') { array_pop($this->requestPath); } } public function getRequestURI() { return $this->requestURI; } public function getRequestPath() { return $this->requestPath; } public function getAppMode() { return $this->appMode; } public function getLogger() { return $this->logger; } public function getControllerPrefix() { return $this->controllerPrefix; } } class ScreenLog { public function __call($methodName, $args) { echo var_export($args, true) . "\n"; } } class RootController { public $home = 'homeController'; public function __invoke($args = array()) { return "Root controller index"; } } $context = new Context([ 'requestURI' => '/', 'logger' => new ScreenLog() ]); $dispatch = new ObjectDispatch(); foreach ($dispatch($context, 'RootController') as $signal) { list($object, $chunk, $path, $isEndpoint) = $signal; if ($isEndpoint) { echo $object->$chunk($path); } }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0160.00316.88
8.3.50.0130.00821.33
8.3.40.0100.01019.04
8.3.30.0040.01118.94
8.3.20.0000.00820.34
8.3.10.0060.00321.82
8.3.00.0040.00422.02
8.2.180.0070.00717.13
8.2.170.0100.01022.96
8.2.160.0100.01020.69
8.2.150.0030.00624.18
8.2.140.0090.00024.66
8.2.130.0000.00826.16
8.2.120.0030.00717.88
8.2.110.0110.00019.32
8.2.100.0090.00318.29
8.2.90.0080.00019.42
8.2.80.0000.00817.97
8.2.70.0080.00317.88
8.2.60.0040.00418.18
8.2.50.0000.01118.09
8.2.40.0040.00422.18
8.2.30.0040.00419.59
8.2.20.0040.00417.96
8.2.10.0000.00818.27
8.2.00.0000.00718.25
8.1.280.0150.00325.92
8.1.270.0040.01122.22
8.1.260.0080.00026.35
8.1.250.0080.00028.09
8.1.240.0000.01022.35
8.1.230.0070.00318.02
8.1.220.0000.00817.93
8.1.210.0040.00418.77
8.1.200.0030.00617.35
8.1.190.0040.00417.35
8.1.180.0000.00918.10
8.1.170.0030.00618.63
8.1.160.0000.00820.80
8.1.150.0040.00419.14
8.1.140.0050.00319.64
8.1.130.0000.00717.76
8.1.120.0000.00717.59
8.1.110.0000.00817.52
8.1.100.0040.00417.49
8.1.90.0040.00417.58
8.1.80.0000.00817.61
8.1.70.0040.00417.59
8.1.60.0060.00317.72
8.1.50.0030.00617.66
8.1.40.0000.00917.54
8.1.30.0060.00317.75
8.1.20.0030.00517.77
8.1.10.0080.00017.65
8.1.00.0030.00617.68
8.0.300.0050.00318.84
8.0.290.0000.00716.88
8.0.280.0070.00018.57
8.0.270.0000.00717.50
8.0.260.0030.00317.31
8.0.250.0040.00317.06
8.0.240.0080.00017.17
8.0.230.0040.00417.05
8.0.220.0020.00517.08
8.0.210.0040.00417.09
8.0.200.0040.00417.09
8.0.190.0040.00417.04
8.0.180.0030.00617.04
8.0.170.0050.00317.11
8.0.160.0000.00817.07
8.0.150.0000.00817.00
8.0.140.0070.00016.93
8.0.130.0040.00713.54
8.0.120.0030.00517.08
8.0.110.0000.00817.12
8.0.100.0000.00817.12
8.0.90.0070.00017.08
8.0.80.0100.00717.07
8.0.70.0040.00417.07
8.0.60.0040.00417.14
8.0.50.0000.00817.20
8.0.30.0120.00617.27
8.0.20.0110.00917.40
8.0.10.0060.00317.28
8.0.00.0090.01117.00
7.4.330.0050.00016.85
7.4.320.0000.00616.63
7.4.300.0020.00516.64
7.4.290.0030.00616.64
7.4.280.0060.00316.74
7.4.270.0070.00016.73
7.4.260.0080.00016.52
7.4.250.0000.00816.50
7.4.240.0000.00716.67
7.4.230.0030.00316.84
7.4.220.0070.01116.73
7.4.210.0120.00416.63
7.4.200.0040.00416.78
7.4.160.0080.00816.71
7.4.150.0110.00817.40
7.4.140.0140.00917.86
7.4.130.0120.00816.86
7.4.120.0110.00916.75
7.4.110.0060.01216.58
7.4.100.0100.00616.46
7.4.90.0110.00716.64
7.4.80.0070.01119.39
7.4.70.0060.01016.83
7.4.60.0110.00716.80
7.4.50.0060.00916.70
7.4.40.0100.01016.78
7.4.30.0150.00316.74
7.4.00.0080.01014.91
7.3.330.0000.00613.40
7.3.320.0030.00313.52
7.3.310.0040.00416.37
7.3.300.0030.00316.44
7.3.290.0030.01216.60
7.3.280.0120.00416.52
7.3.270.0070.01117.40
7.3.260.0120.01216.61
7.3.250.0140.00716.67
7.3.240.0120.00916.47
7.3.230.0110.00716.66
7.3.210.0030.01316.54
7.3.200.0110.00719.39
7.3.190.0060.01316.63
7.3.180.0030.01316.86
7.3.170.0140.00316.59
7.3.160.0060.01016.73
7.3.120.0070.00915.06
7.3.110.0040.01114.97
7.3.100.0100.00415.06
7.3.90.0040.01015.02
7.3.80.0050.00815.19
7.3.70.0030.00815.02
7.3.60.0050.00914.97
7.3.50.0070.00715.02
7.3.40.0050.00914.79
7.3.30.0030.00915.04
7.3.20.0060.00716.73
7.3.10.0050.00916.67
7.3.00.0020.00816.64
7.2.330.0090.00916.96
7.2.320.0000.01816.71
7.2.310.0090.01516.63
7.2.300.0130.01016.58
7.2.290.0130.00316.68
7.2.250.0070.01115.02
7.2.240.0070.00715.15
7.2.230.0020.01315.22
7.2.220.0080.00815.26
7.2.210.0060.00915.24
7.2.200.0030.01115.07
7.2.190.0020.01315.08
7.2.180.0050.00815.22
7.2.170.0030.00915.15
7.2.160.0040.01015.22
7.2.150.0050.01017.03
7.2.140.0070.00416.89
7.2.130.0100.00517.00
7.2.120.0050.00916.92
7.2.110.0090.00516.94
7.2.100.0090.00716.92
7.2.90.0060.00716.86
7.2.80.0060.00616.99
7.2.70.0040.01016.86
7.2.60.0060.00917.04
7.2.50.0040.00616.95
7.2.40.0080.00716.91
7.2.30.0080.00816.95
7.2.20.0050.01016.95
7.2.10.0080.00517.02
7.2.00.0080.00617.60
7.1.330.0050.00915.68
7.1.320.0050.01115.83
7.1.310.0030.00915.78
7.1.300.0060.00715.78
7.1.290.0040.00815.79
7.1.280.0040.00915.75
7.1.270.0060.00815.69
7.1.260.0080.00515.73
7.1.250.0050.01015.64
7.1.240.0070.00715.76
7.1.230.0030.01015.73
7.1.220.0070.00715.66
7.1.210.0060.00615.87
7.1.200.0050.00515.79
7.1.190.0090.00015.78
7.1.180.0070.01115.96
7.1.170.0030.01015.80
7.1.160.0030.01415.69
7.1.150.0060.01015.73
7.1.140.0040.00715.77
7.1.130.0060.00915.80
7.1.120.0000.01615.82
7.1.110.0090.00915.82
7.1.100.0100.00516.94
7.1.90.0090.00615.92
7.1.80.0000.00815.77
7.1.70.0050.01016.21
7.1.60.0080.01017.59
7.1.50.0040.00916.39
7.1.40.0120.00315.75
7.1.30.0040.00815.48
7.1.20.0060.00615.68
7.1.10.0090.00915.57
7.1.00.0030.04518.97
7.0.330.0030.00915.46
7.0.320.0080.00415.33
7.0.310.0040.00715.48
7.0.300.0030.00715.42
7.0.290.0070.01015.48
7.0.280.0000.01315.43
7.0.270.0030.00715.29
7.0.260.0060.01215.35
7.0.250.0000.01515.19
7.0.240.0060.00915.46
7.0.230.0000.01215.43
7.0.220.0090.00615.36
7.0.210.0060.00915.09
7.0.200.0310.00615.26
7.0.190.0030.00615.44
7.0.180.0030.01015.20
7.0.170.0060.00915.54
7.0.160.0030.01315.48
7.0.150.0110.00615.38
7.0.140.0030.01415.48
7.0.130.0050.00515.51
7.0.120.0040.01115.25
7.0.110.0100.00615.50
7.0.100.0060.03717.76
7.0.90.0080.04617.63
7.0.80.0100.03417.73
7.0.70.0000.03517.87
7.0.60.0050.04517.68
7.0.50.0130.04417.82
7.0.40.0020.04716.73
7.0.30.0070.03016.74
7.0.20.0100.04116.70
7.0.10.0070.04716.73
7.0.00.0050.03716.83
5.6.400.0030.01014.91
5.6.390.0030.00714.59
5.6.380.0070.00714.55
5.6.370.0060.00314.11
5.6.360.0030.00614.76
5.6.350.0060.00914.59
5.6.340.0130.00014.83
5.6.330.0000.01414.55
5.6.320.0060.00914.78
5.6.310.0110.00614.67
5.6.300.0080.00814.61
5.6.290.0060.00914.59
5.6.280.0030.02918.00
5.6.270.0030.01314.48
5.6.260.0120.00614.42
5.6.250.0120.03817.56
5.6.240.0110.04317.78
5.6.230.0050.04617.69
5.6.220.0120.02317.61
5.6.210.0190.03517.71
5.6.200.0080.04517.77
5.6.190.0070.04217.70
5.6.180.0060.04317.83
5.6.170.0050.04717.78
5.6.160.0050.04218.02
5.6.150.0090.03717.86
5.6.140.0050.04517.86
5.6.130.0060.04417.79
5.6.120.0070.04517.82
5.6.110.0080.04517.80
5.6.100.0050.04917.93
5.6.90.0060.02417.73
5.6.80.0050.04317.51
5.6.70.0050.03817.59
5.6.60.0080.03817.40
5.6.50.0030.04117.62
5.6.40.0120.03617.32
5.6.30.0080.04117.48
5.6.20.0090.04117.45
5.6.10.0070.04017.58
5.6.00.0080.03217.35
5.5.380.0060.04617.58
5.5.370.0030.02717.42
5.5.360.0190.03517.45
5.5.350.0080.04417.42
5.5.340.0130.04017.48
5.5.330.0050.03117.59
5.5.320.0030.04017.66
5.5.310.0050.04517.64
5.5.300.0070.04617.71
5.5.290.0080.03517.68
5.5.280.0030.05417.56
5.5.270.0100.04317.55
5.5.260.0100.04117.62
5.5.250.0150.05017.40
5.5.240.0140.02417.43
5.5.230.0120.03717.38
5.5.220.0020.04417.38
5.5.210.0090.04017.34
5.5.200.0050.04617.24
5.5.190.0090.03817.21
5.5.180.0070.04217.14
5.5.170.0070.00714.47
5.5.160.0060.03317.22
5.5.150.0030.04917.08
5.5.140.0070.03817.37
5.5.130.0050.02617.33
5.5.120.0050.04017.28
5.5.110.0100.03517.29
5.5.100.0130.03817.28
5.5.90.0080.04317.13
5.5.80.0080.04017.36
5.5.70.0050.04717.25
5.5.60.0120.04217.31
5.5.50.0070.04517.21
5.5.40.0070.04417.28
5.5.30.0060.04417.23
5.5.20.0120.02317.29
5.5.10.0070.02717.18
5.5.00.0120.02017.27

preferences:
53.4 ms | 401 KiB | 5 Q