3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Request { public $answer = 42; public function __construct() { echo 'Request created', PHP_EOL; } } class DI { protected $shared = []; protected $definitions = []; public function __construct() {} public function set($name, $definition, $shared = false) { if($shared) { if(isset($shared[$name])) { throw new Exception("Definition '$name' is already set. Use DI::remove('$name') to remove it."); } $this->shared[$name] = $definition; } else { if(isset($definitions[$name])) { throw new Exception("Definition '$name' is already set. Use DI::remove('$name') to remove it."); } $this->definitions[$name] = $definition; } } public function getRaw($name) { if(!isset($this->definitions[$name])) { throw new Exception("Definition '$name' is not set. Use DI::set('$name', <definition>) to set it."); } return $this->definitions[$name]; } public function get($name) { $definition = $this->getRaw($name); if(is_callable($definition)) return $definition(); if(class_exists($definition)) return new $definition(); } public function getShared($name) { if(!isset($this->shared[$name])) { throw new Exception("Shared definition '$name' is not set. Use DI::set('$name', <definition>, true) to set it."); } $shared = $this->shared[$name]; if(is_callable($shared)) $this->shared[$name] = $shared(); else if(class_exists($shared)) $this->shared[$name] = new $shared(); return $this->shared[$name]; } } $di = new DI(); //Using an anonymous function $di->set('request1', function(){ return new Request(); }, true); //Using an anonymous function $di->set('request2', 'Request', true); $request = $di->getShared('request2'); var_dump($request);

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.0110.00418.31
8.3.50.0140.00521.19
8.3.40.0120.00618.80
8.3.30.0140.00019.21
8.3.20.0080.00020.29
8.3.10.0080.00021.70
8.3.00.0040.00419.38
8.2.180.0120.00316.63
8.2.170.0110.00422.96
8.2.160.0130.00320.39
8.2.150.0030.01724.18
8.2.140.0050.00324.66
8.2.130.0050.00326.16
8.2.120.0060.00322.22
8.2.110.0030.00720.70
8.2.100.0100.00319.58
8.2.90.0080.00018.04
8.2.80.0000.00817.97
8.2.70.0090.00017.75
8.2.60.0050.00317.92
8.2.50.0030.00518.07
8.2.40.0050.00518.22
8.2.30.0070.00018.27
8.2.20.0000.00717.69
8.2.10.0050.00218.09
8.2.00.0040.00417.68
8.1.280.0090.00925.92
8.1.270.0040.00421.97
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0060.00322.36
8.1.230.0000.01321.10
8.1.220.0030.00617.74
8.1.210.0060.00319.15
8.1.200.0070.00317.48
8.1.190.0030.00517.47
8.1.180.0040.00418.10
8.1.170.0050.00318.78
8.1.160.0040.00422.08
8.1.150.0060.00318.89
8.1.140.0070.00017.54
8.1.130.0060.00317.81
8.1.120.0070.00017.43
8.1.110.0040.00417.44
8.1.100.0000.00717.53
8.1.90.0030.00517.48
8.1.80.0000.00717.40
8.1.70.0070.00017.39
8.1.60.0050.00317.52
8.1.50.0050.00317.50
8.1.40.0000.00817.59
8.1.30.0060.00317.75
8.1.20.0000.00817.70
8.1.10.0040.00417.56
8.1.00.0080.00017.60
8.0.300.0000.00720.29
8.0.290.0040.00416.75
8.0.280.0040.00418.51
8.0.270.0040.00417.32
8.0.260.0000.00617.36
8.0.250.0070.00016.92
8.0.240.0040.00417.01
8.0.230.0000.00816.86
8.0.220.0030.00316.96
8.0.210.0030.00316.91
8.0.200.0030.00317.02
8.0.190.0040.00416.89
8.0.180.0000.00816.94
8.0.170.0000.00716.84
8.0.160.0070.00017.02
8.0.150.0000.00716.79
8.0.140.0000.00716.97
8.0.130.0030.00313.42
8.0.120.0050.00316.94
8.0.110.0040.00416.95
8.0.100.0030.00317.00
8.0.90.0070.00017.00
8.0.80.0000.01516.95
8.0.70.0000.00816.98
8.0.60.0030.00516.91
8.0.50.0070.00017.02
8.0.30.0150.00717.17
8.0.20.0170.00517.40
8.0.10.0040.00417.05
8.0.00.0090.01316.77
7.4.330.0020.00215.09
7.4.320.0040.00416.56
7.4.300.0070.00016.50
7.4.290.0080.00016.65
7.4.280.0000.00816.64
7.4.270.0070.00016.48
7.4.260.0000.00716.50
7.4.250.0000.00716.67
7.4.240.0060.00116.69
7.4.230.0000.00716.76
7.4.220.0160.00916.68
7.4.210.0100.00316.54
7.4.200.0070.00016.56
7.4.160.0120.00316.68
7.4.150.0190.00017.40
7.4.140.0170.00317.86
7.4.130.0100.00716.65
7.4.120.0090.00916.59
7.4.110.0110.00616.51
7.4.100.0000.01716.62
7.4.90.0100.00716.57
7.4.80.0080.00919.39
7.4.70.0140.00916.56
7.4.60.0030.01416.64
7.4.50.0030.00516.37
7.4.40.0080.00816.69
7.4.30.0100.00816.48
7.4.00.0060.00915.28
7.3.330.0020.00213.25
7.3.320.0050.00013.36
7.3.310.0030.00316.29
7.3.300.0070.00016.40
7.3.290.0080.01116.37
7.3.280.0060.01116.40
7.3.270.0110.01117.40
7.3.260.0110.00816.64
7.3.250.0030.01316.50
7.3.240.0090.01316.64
7.3.230.0170.00316.70
7.3.210.0030.01316.55
7.3.200.0000.01716.42
7.3.190.0060.01516.73
7.3.180.0090.00616.48
7.3.170.0060.00916.37
7.3.160.0080.00816.57
7.2.330.0070.01016.49
7.2.320.0090.00816.38
7.2.310.0030.01416.82
7.2.300.0110.00616.66
7.2.290.0060.01316.61
7.2.00.0130.01019.63
7.1.100.0040.00817.93
7.1.70.0000.00717.09
7.1.60.0100.01419.11
7.1.50.0160.01017.11
7.1.00.0000.08022.30
7.0.200.0000.00916.52
7.0.140.0000.07322.07
7.0.60.0130.06319.98
7.0.50.0130.07017.92
7.0.40.0100.08320.27
7.0.30.0270.07720.26
7.0.20.0430.07020.08
7.0.10.0070.04320.21
7.0.00.0070.09320.33
5.6.280.0000.07721.09
5.6.210.0030.07020.52
5.6.200.0070.07718.13
5.6.190.0100.07320.41
5.6.180.3600.03320.55
5.6.170.0270.07720.48
5.6.160.0070.08320.46
5.6.150.0030.07718.24
5.6.140.0100.08018.26
5.6.130.0130.04718.16
5.6.120.0000.04721.15
5.6.110.0100.08021.03
5.6.100.0030.09320.95
5.6.90.0070.05021.10
5.6.80.0130.07720.53
5.6.70.4170.03720.43
5.5.350.0100.04720.45
5.5.340.0000.05017.99
5.5.330.0100.04320.57
5.5.320.4070.04320.27
5.5.310.0200.05320.19
5.5.300.0070.07718.08
5.5.290.0100.05017.94
5.5.280.0170.06720.79
5.5.270.0100.08020.89
5.5.260.0070.04320.81
5.5.250.0100.07720.73
5.5.240.0230.07020.38
5.4.450.0100.05719.60
5.4.440.0500.05319.54
5.4.430.0100.06719.45
5.4.420.0670.00019.42
5.4.410.0630.00019.33
5.4.400.0630.00019.04
5.4.390.0630.00019.21
5.4.380.0630.00019.09
5.4.370.0630.00019.21
5.4.360.0630.00019.26
5.4.350.0630.00019.07
5.4.340.0060.03412.03
5.4.320.0050.03712.52
5.4.310.0030.04012.52
5.4.300.0060.03712.52
5.4.290.0090.03512.52
5.4.280.0040.03712.41
5.4.270.0020.04012.41
5.4.260.0020.04112.41
5.4.250.0070.03612.41
5.4.240.0060.03912.41
5.4.230.0050.04812.40
5.4.220.0040.03812.40
5.4.210.0100.03112.40
5.4.200.0050.03812.40
5.4.190.0060.03512.40
5.4.180.0050.03612.40
5.4.170.0040.03812.41
5.4.160.0040.03712.40
5.4.150.0080.03412.40
5.4.140.0080.03512.09
5.4.130.0090.03512.07
5.4.120.0050.04912.04
5.4.110.0030.04012.02
5.4.100.0050.03512.03
5.4.90.0060.03612.03
5.4.80.0060.03612.03
5.4.70.0060.03412.02
5.4.60.0030.03712.02
5.4.50.0070.03312.02
5.4.40.0060.03412.01
5.4.30.0030.03712.01
5.4.20.0030.03812.01
5.4.10.0050.03412.01
5.4.00.0090.03211.49
5.3.290.0080.03612.80
5.3.280.0060.03712.71
5.3.270.0020.04612.73
5.3.260.0100.03412.71
5.3.250.0040.03812.72
5.3.240.0070.03412.72
5.3.230.0050.03712.71
5.3.220.0070.03512.68
5.3.210.0040.04012.68
5.3.200.0040.03712.68
5.3.190.0050.03712.68
5.3.180.0080.03312.68
5.3.170.0050.03712.67
5.3.160.0070.03412.68
5.3.150.0100.03112.68
5.3.140.0040.03812.66
5.3.130.0040.04412.66
5.3.120.0040.04012.66
5.3.110.0100.03412.66
5.3.100.0050.03712.13
5.3.90.0050.03712.11
5.3.80.0070.03512.09
5.3.70.0040.03812.09
5.3.60.0070.03612.08
5.3.50.0040.03912.02
5.3.40.0030.03912.02
5.3.30.0060.03511.98
5.3.20.0030.03811.76
5.3.10.0080.03311.73
5.3.00.0030.03811.72
5.2.170.0060.0299.22
5.2.160.0060.0279.23
5.2.150.0070.0289.22
5.2.140.0030.0379.22
5.2.130.0100.0259.18
5.2.120.0050.0299.18
5.2.110.0030.0309.18
5.2.100.0060.0269.18
5.2.90.0060.0279.18
5.2.80.0020.0329.18
5.2.70.0060.0289.17
5.2.60.0040.0309.13
5.2.50.0060.0289.10
5.2.40.0040.0299.08
5.2.30.0020.0329.04
5.2.20.0060.0279.04
5.2.10.0030.0298.95
5.2.00.0050.0288.81
5.1.60.0050.0238.10
5.1.50.0000.0298.09
5.1.40.0030.0258.07
5.1.30.0020.0288.42
5.1.20.0050.0298.44
5.1.10.0030.0268.17
5.1.00.0030.0268.17
5.0.50.0030.0206.64
5.0.40.0060.0166.51
5.0.30.0020.0326.31
5.0.20.0000.0226.28
5.0.10.0040.0196.26
5.0.00.0040.0306.26
4.4.90.0020.0164.78
4.4.80.0050.0134.76
4.4.70.0020.0164.76
4.4.60.0020.0154.75
4.4.50.0030.0144.77
4.4.40.0000.0294.71
4.4.30.0030.0194.76
4.4.20.0020.0164.84
4.4.10.0010.0164.85
4.4.00.0010.0264.76
4.3.110.0020.0164.67
4.3.100.0030.0144.66
4.3.90.0010.0164.63
4.3.80.0030.0244.59
4.3.70.0010.0164.63
4.3.60.0020.0154.63
4.3.50.0030.0154.63
4.3.40.0040.0234.54
4.3.30.0020.0153.30
4.3.20.0010.0163.28
4.3.10.0000.0173.24
4.3.00.0070.0207.89

preferences:
40.57 ms | 401 KiB | 5 Q