3v4l.org

run code in 300+ PHP versions simultaneously
<?php class objectDispatch { public function routeIterator(&$path) { while (!empty($path)) { yield end($path); array_pop($path); } } public function __invoke($context, $root) { $last = ''; $parent = null; $current = $root; $isEndpoint = false; foreach($this->routeIterator($path) as $chunk) { if (!is_object($current) && class_exists($current)) { $current = new $current(); } if (is_object($current)) { $parent = $current; } if (in_array($chunk, get_class_methods($parent))) { yield $parent->$chunk($path); $isEndpoint = true; break; } else if (array_key_exists($chunk, get_object_vars($parent))) { $current = $parent->$chunk; } else if (method_exists($parent, 'lookup')) { list($current, $consumed) = $parent->lookup($path); $chunk = implode('/', $consumed); $truncateAt = count($consumed); array_splice($path, $truncateAt, ($truncateAt - count($path))); } else { header('Http/1.0 404 Not Found'); exit(); } $last = $chunk; } //No parts remaining if (!is_object($current) && class_exists($current)) { $current = new $current(); } if (!$isEndpoint) { if (is_object($current)) { yield $current(); } else if (is_object($parent)) { yield $parent(); } } } } class context { public $requestPath; public $trailing; public function __construct($path) { $this->trailing = false; $requestPath = explode('/', $path); if (end($path) == '') { $this->trailing = (count($path) > 2); array_pop($path); } $path = array_reverse($path); if (end($path) == '') { //Eliminate leading slashes array_pop($path); } $this->requestPath = $path; } } class rootController { public $admin = 'adminController'; public function __invoke($args = []) { return "hello from root"; } } class adminController { public $user = 'usersController'; public function __invoke($args = []) { return "hello from admin"; } } class usersController { public function __invoke($args = []) { return "hello from users"; } public function lookup($path) { $current = new userController($path[0]); return [$current, [$path[0]]]; } } class userController { public $id; public function __construct($id) { $this->id = $id; } public function __invoke($args = []) { return "hello from user " . $this->id; } } $context = new context('/admin/user/'); $dispatch = new objectDispatch(); foreach ($dispatch($context, 'rootController') as $dispatchMessage) { echo $dispatchMessage; }

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.0140.00717.00
8.3.50.0140.00716.59
8.3.40.0040.01118.71
8.3.30.0150.00018.84
8.3.20.0090.00020.30
8.3.10.0040.00423.62
8.3.00.0040.00420.77
8.2.180.0150.00917.00
8.2.170.0100.00722.96
8.2.160.0070.00720.49
8.2.150.0000.00824.18
8.2.140.0040.00424.66
8.2.130.0040.00419.37
8.2.120.0030.00526.35
8.2.110.0060.00322.16
8.2.100.0040.00817.91
8.2.90.0000.00819.09
8.2.80.0000.00817.97
8.2.70.0060.00317.63
8.2.60.0030.00817.78
8.2.50.0050.00318.07
8.2.40.0000.00822.29
8.2.30.0070.00020.66
8.2.20.0050.00217.61
8.2.10.0040.00418.05
8.2.00.0040.00418.14
8.1.280.0080.00825.92
8.1.270.0200.00020.37
8.1.260.0070.00028.09
8.1.250.0060.00328.09
8.1.240.0030.00622.04
8.1.230.0120.00019.06
8.1.220.0030.00617.79
8.1.210.0040.00418.77
8.1.200.0060.00317.23
8.1.190.0050.00317.23
8.1.180.0000.00718.10
8.1.170.0080.00018.46
8.1.160.0040.00420.75
8.1.150.0040.00418.89
8.1.140.0040.00419.55
8.1.130.0070.00017.67
8.1.120.0040.00417.48
8.1.110.0000.00817.46
8.1.100.0000.00817.48
8.1.90.0040.00417.45
8.1.80.0040.00417.46
8.1.70.0020.00517.38
8.1.60.0080.00017.54
8.1.50.0060.00317.60
8.1.40.0040.00417.45
8.1.30.0000.00817.65
8.1.20.0040.00417.61
8.1.10.0000.00817.50
8.1.00.0060.00317.54
8.0.300.0040.00418.77
8.0.290.0040.00416.63
8.0.280.0030.00518.35
8.0.270.0050.00217.16
8.0.260.0000.00717.14
8.0.250.0030.00316.98
8.0.240.0060.00016.87
8.0.230.0080.00016.97
8.0.220.0040.00416.84
8.0.210.0080.00016.81
8.0.200.0000.00617.03
8.0.190.0050.00317.00
8.0.180.0030.00316.88
8.0.170.0000.00816.98
8.0.160.0040.00416.86
8.0.150.0040.00416.79
8.0.140.0080.00016.83
8.0.130.0000.00513.30
8.0.120.0040.00416.86
8.0.110.0070.00016.89
8.0.100.0050.00316.81
8.0.90.0000.00716.93
8.0.80.0080.01416.94
8.0.70.0070.00017.00
8.0.60.0040.00416.90
8.0.50.0000.00816.84
8.0.30.0050.01217.01
8.0.20.0080.01117.40
8.0.10.0000.00716.88
8.0.00.0150.00516.89
7.4.330.0060.00016.76
7.4.320.0060.00016.54
7.4.300.0000.00716.53
7.4.290.0000.01116.45
7.4.280.0030.00616.53
7.4.270.0000.00716.69
7.4.260.0040.00416.45
7.4.250.0060.00316.50
7.4.240.0020.00516.63
7.4.230.0070.00016.68
7.4.220.0180.00916.55
7.4.210.0070.01116.76
7.4.200.0040.00416.60
7.4.160.0060.00916.46
7.4.150.0090.00917.40
7.4.140.0110.01017.86
7.4.130.0080.00916.62
7.4.120.0110.00916.49
7.4.110.0110.00716.61
7.4.100.0080.01216.52
7.4.90.0120.00916.66
7.4.80.0130.00919.39
7.4.70.0050.01116.45
7.4.60.0100.00716.64
7.4.50.0030.01016.22
7.4.40.0100.00716.62
7.4.30.0090.01316.79
7.4.00.0030.01014.91
7.3.330.0030.00313.46
7.3.320.0000.00513.43
7.3.310.0000.00816.32
7.3.300.0050.00316.34
7.3.290.0090.01016.46
7.3.280.0090.00616.47
7.3.270.0120.00617.40
7.3.260.0120.00616.51
7.3.250.0090.01316.61
7.3.240.0030.01316.55
7.3.230.0090.00916.43
7.3.210.0110.00716.50
7.3.200.0140.00316.45
7.3.190.0120.00416.48
7.3.180.0150.00616.53
7.3.170.0060.01216.54
7.3.160.0090.00616.46
7.2.330.0090.00916.84
7.2.320.0120.01016.71
7.2.310.0100.00716.52
7.2.300.0060.01216.55
7.2.290.0130.00316.75
7.2.60.0000.01517.11
7.2.00.0060.00619.66
7.1.200.0060.00616.05
7.1.100.0040.00818.29
7.1.70.0030.01317.21
7.1.60.0070.01419.52
7.1.50.0030.00917.02
7.1.00.0070.07322.48
7.0.200.0040.00416.70
7.0.60.0070.03720.01
7.0.50.0030.07717.86
7.0.40.0030.04320.13
7.0.30.0170.04320.34
7.0.20.0400.07720.15
7.0.10.0130.05720.23
7.0.00.0100.05020.25
5.6.280.0030.04020.94
5.6.210.0130.07020.47
5.6.200.0030.05718.15
5.6.190.0100.04720.63
5.6.180.0230.04720.67
5.6.170.0200.06020.50
5.6.160.0030.07020.57
5.6.150.0130.07718.28
5.6.140.0030.07018.25
5.6.130.0030.06718.17
5.6.120.0000.09321.17
5.6.110.0070.04021.14
5.6.100.0100.07721.12
5.6.90.0070.09721.13
5.6.80.0200.07020.40
5.5.350.3870.04020.38
5.5.340.0130.04017.96
5.5.330.0070.05320.56
5.5.320.0200.05720.33
5.5.310.0130.05020.32
5.5.300.0100.03717.98
5.5.290.0030.08717.96
5.5.280.0000.05720.68
5.5.270.0030.04320.89
5.5.260.0030.04020.67
5.5.250.0170.05720.69
5.5.240.4130.03720.21

preferences:
58.44 ms | 401 KiB | 5 Q