3v4l.org

run code in 300+ PHP versions simultaneously
<?php # basic container class Container { private $raw; // callbacks private $values; // objects private $locked; public function __construct(array $config = []) { foreach($config as $id => $callback){ $this->set($id, $callback); } } public function set(string $id, callable $callback): void { if(isset($this->locked[$id])){ throw new LockedIdException(); } $this->raw[$id] = $callback; } public function get(string $id) { if(!isset($this->raw[$id])){ throw new UnknownIdException(); } if(isset($this->values[$id])){ return $this->values[$id]; } $cb = $this->raw[$id]; $val = $this->values[$id] = $cb($this); $this->locked[$id] = true; return $val; } public function has(string $id): bool { return isset($this->values[$id]); } } class Resolver { public function __construct(Container $container, WireRule ...$rules) { $this->c = $container; $this->rules = $rules; } public function get(string $class) { if(!$this->c->has($class)){ $this->c->set($class, $this->resolve($class)); } return $this->c->get($class); } public function resolve(string $class): callable { if(!class_exists($class)){ throw new UnknownIdException(); } if(!method_exists($class, '__construct')){ return function(Container $c) use ($class){ return new $class; }; } $constructor = new \ReflectionMethod($class, '__construct'); if(count($params = $constructor->getParameters()) === 0){ return function(Container $c) use ($class){ return new $class; }; } foreach($params as $param){ $args[] = $param->hasType() ? $this->getArgument($param->getType()->__toString()) : null; } return function(Container $c) use ($class, $args){ return new $class(...$args); }; } public function getArgument(string $type) { foreach($this->rules as $rule){ if($rule->match($type)){ $type = $rule->getWiredClass($type); } } return $type ? $this->get($type) : null; } } class Foo { public function __construct(Bar $bar){ $this->bar = $bar; }} class Bar { public function __construct(Baz $baz){ $this->baz = $baz; }} class Joe { public $bob = 'bob'; } class Baz {} $c = new Resolver(new Container); var_dump($c->get(Foo::class)); var_dump($c->get(Baz::class)); var_dump($c->get(Joe::class));

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.0120.00318.43
8.3.50.0120.00316.64
8.3.40.0120.00318.70
8.3.30.0120.00318.88
8.3.20.0000.00819.11
8.3.10.0080.00020.90
8.3.00.0060.00319.68
8.2.180.0220.00016.88
8.2.170.0040.01122.96
8.2.160.0060.00919.20
8.2.150.0000.00824.18
8.2.140.0040.00424.66
8.2.130.0040.00419.82
8.2.120.0040.01126.35
8.2.110.0060.00322.18
8.2.100.0080.00417.84
8.2.90.0080.00017.88
8.2.80.0000.00918.95
8.2.70.0030.00617.50
8.2.60.0040.00417.63
8.2.50.0080.00017.63
8.2.40.0060.00319.48
8.2.30.0040.00419.58
8.2.20.0000.00718.10
8.2.10.0030.00518.18
8.2.00.0040.00421.19
8.1.280.0140.00325.92
8.1.270.0040.00423.96
8.1.260.0050.00326.35
8.1.250.0000.00828.09
8.1.240.0030.00623.83
8.1.230.0040.00719.15
8.1.220.0040.00417.79
8.1.210.0000.00918.77
8.1.200.0040.00417.38
8.1.190.0100.00017.48
8.1.180.0040.00418.10
8.1.170.0090.00017.62
8.1.160.0050.00218.97
8.1.150.0040.00418.94
8.1.140.0050.00217.60
8.1.130.0000.00718.97
8.1.120.0000.00717.56
8.1.110.0030.00517.49
8.1.100.0000.00717.53
8.1.90.0000.00917.48
8.1.80.0070.00017.46
8.1.70.0030.00317.56
8.1.60.0060.00317.52
8.1.50.0040.00717.49
8.1.40.0040.00417.47
8.1.30.0080.00417.68
8.1.20.0080.00017.60
8.1.10.0040.00417.58
8.1.00.0030.00617.55
8.0.300.0040.00418.77
8.0.290.0000.00817.00
8.0.280.0000.00718.42
8.0.270.0000.00717.32
8.0.260.0100.00017.31
8.0.250.0000.00716.95
8.0.240.0080.00017.12
8.0.230.0040.00417.08
8.0.220.0000.00916.87
8.0.210.0040.00417.01
8.0.200.0000.00617.07
8.0.190.0030.00617.05
8.0.180.0000.00816.98
8.0.170.0040.00416.91
8.0.160.0040.00417.03
8.0.150.0070.00017.00
8.0.140.0070.00016.97
8.0.130.0000.00613.43
8.0.120.0000.00716.96
8.0.110.0070.00016.97
8.0.100.0000.00816.94
8.0.90.0000.00817.02
8.0.80.0110.00416.98
8.0.70.0000.00717.04
8.0.60.0040.00417.02
8.0.50.0040.00417.05
8.0.30.0070.01417.13
8.0.20.0090.01117.40
8.0.10.0050.00317.11
8.0.00.0080.01216.83
7.4.330.0030.00315.55
7.4.320.0040.00416.56
7.4.300.0030.00316.54
7.4.290.0070.00016.52
7.4.280.0000.00716.64
7.4.270.0000.00716.39
7.4.260.0050.00216.45
7.4.250.0040.00416.49
7.4.240.0000.00716.69
7.4.230.0000.00716.65
7.4.220.0000.00716.64
7.4.210.0060.00916.58
7.4.200.0040.00416.63
7.4.160.0060.01016.67
7.4.140.0120.00817.86
7.4.130.0110.00616.55
7.4.120.0100.01116.56
7.4.110.0030.01316.56
7.4.100.0060.01516.39
7.4.90.0110.00716.47
7.4.80.0180.00019.39
7.4.70.0110.00516.71
7.4.60.0130.00616.65
7.4.50.0060.00816.50
7.4.40.0130.00316.31
7.4.10.0060.01214.92
7.4.00.0060.01115.10
7.3.330.0000.00613.26
7.3.320.0000.00613.41
7.3.310.0030.00316.45
7.3.300.0030.00516.45
7.3.290.0000.00816.27
7.3.280.0070.01116.39
7.3.260.0100.00916.47
7.3.240.0090.00816.44
7.3.230.0110.01116.44
7.3.210.0030.01416.55
7.3.200.0120.00616.30
7.3.190.0080.00916.44
7.3.180.0060.01016.42
7.3.170.0110.00516.63
7.3.160.0070.01116.50
7.3.130.0070.01014.80
7.3.120.0020.01314.77
7.3.110.0090.00714.71
7.3.100.0070.00614.86
7.3.90.0070.00714.83
7.3.80.0050.00714.91
7.3.70.0060.01014.81
7.3.60.0120.00314.85
7.3.50.0030.00814.94
7.3.40.0070.00514.83
7.3.30.0070.00514.84
7.3.20.0040.01116.83
7.3.10.0030.00916.47
7.3.00.0070.00516.64
7.2.330.0090.02116.47
7.2.320.0080.01216.71
7.2.310.0060.01216.56
7.2.300.0080.01116.84
7.2.290.0130.00616.62
7.2.260.0080.01215.11
7.2.250.0060.00815.28
7.2.240.0080.00815.06
7.2.230.0030.00915.12
7.2.220.0020.00915.29
7.2.210.0080.00815.05
7.2.200.0100.00515.20
7.2.190.0050.01015.10
7.2.180.0050.01014.98
7.2.170.0050.00915.24
7.2.160.0030.01115.08
7.2.150.0030.00716.89
7.2.140.0100.00317.00
7.2.130.0100.00617.07
7.2.120.0070.00716.95
7.2.110.0030.01216.83
7.2.100.0110.00317.06
7.2.90.0070.01016.90
7.2.80.0110.00317.06
7.2.70.0110.00416.87
7.2.60.2050.00616.19
7.2.50.2160.00916.04
7.2.40.1940.00715.99
7.2.30.2100.01216.17
7.2.20.1750.00916.17
7.2.10.1750.00616.24
7.2.00.1580.00816.29
7.1.330.0050.00815.83
7.1.320.0020.01215.95
7.1.310.0030.01115.74
7.1.300.0050.00815.62
7.1.290.0040.00915.93
7.1.280.0030.00815.85
7.1.270.0020.01015.74
7.1.260.0030.01215.76
7.1.250.0080.00815.76
7.1.240.0070.00715.77
7.1.230.0060.01215.95
7.1.220.0070.00715.98
7.1.210.0080.00415.85
7.1.200.0050.00715.75
7.1.190.0060.00616.00
7.1.180.0060.00615.93
7.1.170.1670.00815.00
7.1.160.1820.00716.51
7.1.150.1990.00916.40
7.1.140.1860.00816.26
7.1.130.1810.01016.45
7.1.120.1480.01216.32
7.1.110.1860.01015.98
7.1.100.1660.00516.23
7.1.90.2020.01315.85
7.1.80.1810.01216.02
7.1.70.1910.00715.73
7.1.60.2100.00824.68
7.1.50.2760.00824.48
7.1.40.2390.00924.23
7.1.30.2240.01024.19
7.1.20.3350.01224.40
7.1.10.2840.01115.12
7.1.00.2170.01015.44
7.0.330.0070.00715.58
7.0.320.0040.00715.45
7.0.310.0070.00715.43
7.0.300.0070.01015.59
7.0.290.0030.01315.60
7.0.280.0040.00715.29
7.0.270.0000.01115.44
7.0.260.0030.00715.12
7.0.250.0070.00415.58
7.0.240.0070.00715.60
7.0.230.0030.01015.54
7.0.220.0060.00815.47
7.0.210.0000.00815.48
7.0.200.0040.00415.52
7.0.190.0080.00615.39
7.0.180.0040.00815.47
7.0.170.0000.01515.50
7.0.160.0090.00315.39
7.0.150.0000.00815.19
7.0.140.0090.00615.18
7.0.130.0090.00915.19
7.0.120.0030.01315.70
7.0.110.0060.01015.61
7.0.100.0120.00415.39
7.0.90.0060.00915.42
7.0.80.0090.00615.24
7.0.70.0000.01815.10
7.0.60.0070.01015.46
7.0.50.0110.00015.46
7.0.40.0040.01213.46
7.0.30.0040.01113.64
7.0.20.0000.01413.55
7.0.10.0000.01513.53
7.0.00.0070.00713.48
5.6.400.0070.00414.01
5.6.390.0000.01614.34
5.6.380.0070.00314.01
5.6.370.0090.00614.52
5.6.360.0000.01214.39
5.6.350.0040.01414.22
5.6.340.0090.00314.06
5.6.330.0070.01013.92
5.6.320.0130.00313.95
5.6.310.0030.01014.44
5.6.300.0090.00314.03
5.6.290.0060.01214.30
5.6.280.0040.01214.27
5.6.270.0100.00714.39
5.6.260.0070.00414.18
5.6.250.0090.00614.07
5.6.240.0070.01014.25
5.6.230.0040.00814.25
5.6.220.0070.01113.92
5.6.210.0040.00814.07
5.6.200.0030.01414.38
5.6.190.0000.01614.00
5.6.180.0000.01314.25
5.6.170.0040.00414.21
5.6.160.0110.00414.36
5.6.150.0030.00914.15
5.6.140.0000.01414.07
5.6.130.0040.01114.25
5.6.120.0070.00714.33
5.6.110.0070.00314.07
5.6.100.0060.01214.14
5.6.90.0090.00014.13
5.6.80.0110.00414.07
5.6.70.0000.01114.04
5.6.60.0070.00714.09
5.6.50.0060.00913.95
5.6.40.0070.00314.14
5.6.30.0030.00614.13
5.6.20.0110.00413.91
5.6.10.0090.00613.81
5.6.00.0000.01213.77

preferences:
70.96 ms | 401 KiB | 5 Q