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(is_string($shared) && 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'); $request->answer = 5; var_dump($di->getShared('request2'));

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.00318.30
8.3.50.0140.00821.27
8.3.40.0100.00718.71
8.3.30.0070.00719.08
8.3.20.0000.00820.19
8.3.10.0080.00021.95
8.3.00.0040.00419.38
8.2.180.0060.00916.50
8.2.170.0190.00322.96
8.2.160.0040.01219.20
8.2.150.0080.00024.18
8.2.140.0040.00424.66
8.2.130.0030.00626.16
8.2.120.0080.00022.22
8.2.110.0030.00720.38
8.2.100.0110.00017.97
8.2.90.0080.00018.14
8.2.80.0000.00817.97
8.2.70.0040.00417.63
8.2.60.0050.00317.93
8.2.50.0000.00818.07
8.2.40.0040.00419.95
8.2.30.0080.00018.26
8.2.20.0050.00317.87
8.2.10.0000.00718.19
8.2.00.0040.00417.68
8.1.280.0110.00725.92
8.1.270.0060.00322.30
8.1.260.0050.00226.35
8.1.250.0040.00428.09
8.1.240.0060.00322.10
8.1.230.0000.01120.89
8.1.220.0050.00317.74
8.1.210.0090.00019.06
8.1.200.0040.00817.48
8.1.190.0060.00317.35
8.1.180.0080.00018.10
8.1.170.0000.00818.80
8.1.160.0040.00422.07
8.1.150.0000.00818.93
8.1.140.0030.00617.53
8.1.130.0040.00417.89
8.1.120.0000.00717.55
8.1.110.0040.00417.41
8.1.100.0030.00517.56
8.1.90.0070.00017.53
8.1.80.0040.00417.49
8.1.70.0000.00717.53
8.1.60.0040.00417.63
8.1.50.0050.00317.54
8.1.40.0030.00517.54
8.1.30.0040.00417.77
8.1.20.0030.00617.73
8.1.10.0000.00817.64
8.1.00.0000.00917.53
8.0.300.0040.00420.21
8.0.290.0080.00016.75
8.0.280.0000.00718.61
8.0.270.0040.00417.18
8.0.260.0000.00617.37
8.0.250.0000.00716.93
8.0.240.0000.00817.04
8.0.230.0030.00316.87
8.0.220.0070.00016.97
8.0.210.0030.00316.88
8.0.200.0030.00317.05
8.0.190.0050.00217.07
8.0.180.0000.00716.98
8.0.170.0000.00816.98
8.0.160.0050.00216.99
8.0.150.0080.00016.88
8.0.140.0070.00016.80
8.0.130.0060.00013.39
8.0.120.0070.00016.91
8.0.110.0000.00716.82
8.0.100.0040.00416.95
8.0.90.0050.00317.06
8.0.80.0070.01016.99
8.0.70.0030.00516.77
8.0.60.0000.00816.92
8.0.50.0040.00416.83
8.0.30.0080.01116.96
8.0.20.0110.00817.40
8.0.10.0000.00817.03
8.0.00.0100.01017.01
7.4.330.0050.00015.08
7.4.320.0060.00016.52
7.4.300.0030.00316.66
7.4.290.0000.00716.63
7.4.280.0030.00516.58
7.4.270.0000.00716.67
7.4.260.0030.00316.64
7.4.250.0030.00316.61
7.4.240.0020.00516.55
7.4.230.0030.00316.68
7.4.220.0140.00416.58
7.4.210.0070.00716.56
7.4.200.0070.00016.66
7.4.160.0090.00616.32
7.4.150.0110.00717.40
7.4.140.0080.01117.86
7.4.130.0160.00316.60
7.4.120.0090.01216.65
7.4.110.0110.00716.40
7.4.100.0090.00916.63
7.4.90.0070.01016.58
7.4.80.0080.01519.39
7.4.70.0060.01216.51
7.4.60.0050.01316.46
7.4.50.0000.00816.41
7.4.40.0000.01716.55
7.4.30.0130.00316.70
7.4.00.0090.00715.13
7.3.330.0000.00513.27
7.3.320.0000.00513.43
7.3.310.0050.00516.52
7.3.300.0070.00016.33
7.3.290.0040.01116.42
7.3.280.0100.01116.40
7.3.270.0070.01117.40
7.3.260.0150.00316.41
7.3.250.0080.00816.49
7.3.240.0140.00916.41
7.3.230.0040.01616.64
7.3.210.0060.00916.34
7.3.200.0130.00316.56
7.3.190.0030.01616.43
7.3.180.0030.01316.43
7.3.170.0140.00316.30
7.3.160.0060.01016.68
7.3.120.0070.01115.10
7.3.110.0070.01015.05
7.3.100.0040.01214.58
7.3.90.0080.00814.86
7.3.80.0080.00814.85
7.3.70.0040.00714.79
7.3.60.0030.01214.75
7.3.50.0040.00914.91
7.3.40.0040.00714.96
7.3.30.0000.01314.94
7.3.20.0070.00416.93
7.3.10.0090.00716.76
7.3.00.0090.00516.70
7.2.330.0130.00716.54
7.2.320.0120.00616.80
7.2.310.0140.00916.71
7.2.300.0060.01216.79
7.2.290.0070.01716.90
7.2.250.0030.01015.07
7.2.240.0070.01014.98
7.2.230.0070.00715.11
7.2.220.0030.01014.88
7.2.210.0090.00915.07
7.2.200.0030.01015.07
7.2.190.0060.00915.02
7.2.180.0030.01015.11
7.2.170.0060.00915.17
7.2.130.0060.00816.77
7.2.120.0130.00316.95
7.2.110.0080.00616.80
7.2.100.0000.01117.00
7.2.90.0040.00816.81
7.2.80.0060.00616.75
7.2.70.0030.00617.15
7.2.60.0040.01116.89
7.2.50.0100.00317.09
7.2.40.0090.00616.55
7.2.30.0090.00616.82
7.2.20.0040.01116.99
7.2.10.0060.00617.13
7.2.00.0090.00617.02
7.1.330.0100.00315.77
7.1.320.0100.00315.58
7.1.310.0070.01115.44
7.1.300.0100.00315.81
7.1.290.0030.01315.79
7.1.280.0030.01415.87
7.1.270.0000.01015.80
7.1.260.0000.01215.71
7.1.250.0090.00016.05
7.1.70.0030.00317.07
7.1.60.0100.01419.11
7.1.50.0120.01217.08
7.1.00.0030.07722.45
7.0.200.0000.00916.94
7.0.140.0070.07021.95
7.0.60.0070.08020.00
7.0.50.0000.04317.93
7.0.40.0100.06020.25
7.0.30.0230.05320.28
7.0.20.0230.07720.24
7.0.10.0070.07020.10
7.0.00.0130.04720.10
5.6.280.0100.06720.94
5.6.210.0100.05720.54
5.6.200.0070.08318.18
5.6.190.0170.07720.39
5.6.180.0130.04320.39
5.6.170.0230.04020.54
5.6.160.0170.07720.54
5.6.150.0030.08318.18
5.6.140.0030.08318.18
5.6.130.0030.04318.24
5.6.120.0000.05720.91
5.6.110.0130.07321.01
5.6.100.0030.04021.01
5.6.90.0030.04321.05
5.6.80.0070.06720.37
5.5.350.4200.04320.49
5.5.340.0100.07718.08
5.5.330.0070.06320.25
5.5.320.0230.04720.21
5.5.310.0230.03720.27
5.5.300.0070.07718.04
5.5.290.0130.05317.98
5.5.280.0100.08321.00
5.5.270.0070.06020.86
5.5.260.0100.08020.89
5.5.250.0070.03720.63
5.5.240.0200.07020.25
5.4.450.0100.06719.55
5.4.440.0800.05319.59
5.4.430.0300.07019.66
5.4.420.0630.00019.51
5.4.410.0630.00019.52
5.4.400.0630.00019.12
5.4.390.0630.00019.12
5.4.380.0630.00019.11
5.4.370.0630.00019.21
5.4.360.0600.00019.16
5.4.350.0670.00019.12
5.4.340.0050.03512.02
5.4.320.0050.03812.52
5.4.310.0050.04012.52
5.4.300.0110.03212.52
5.4.290.0070.03812.51
5.4.280.0040.03712.41
5.4.270.0070.04312.41
5.4.260.0120.04212.41
5.4.250.0060.03812.41
5.4.240.0050.03812.41
5.4.230.0090.03512.41
5.4.220.0050.03712.41
5.4.210.0090.03312.40
5.4.200.0060.03712.40
5.4.190.0060.03612.40
5.4.180.0080.03412.39
5.4.170.0060.03612.41
5.4.160.0050.03612.41
5.4.150.0050.03712.41
5.4.140.0050.03712.09
5.4.130.0100.03112.07
5.4.120.0070.03412.03
5.4.110.0030.03912.03
5.4.100.0090.03212.03
5.4.90.0040.03912.03
5.4.80.0050.03812.03
5.4.70.0040.04012.03
5.4.60.0030.03712.03
5.4.50.0060.03612.03
5.4.40.0040.03712.02
5.4.30.0060.03512.01
5.4.20.0060.03412.01
5.4.10.0080.03112.01
5.4.00.0040.03711.49
5.3.290.0050.04212.80
5.3.280.0080.03412.71
5.3.270.0060.04312.72
5.3.260.0040.04112.72
5.3.250.0090.03512.72
5.3.240.0070.03912.72
5.3.230.0060.03712.71
5.3.220.0050.03812.68
5.3.210.0090.03912.68
5.3.200.0070.03612.68
5.3.190.0060.03612.68
5.3.180.0050.03712.67
5.3.170.0050.03712.67
5.3.160.0050.03712.67
5.3.150.0040.03912.67
5.3.140.0070.03512.66
5.3.130.0060.03812.66
5.3.120.0030.04312.66
5.3.110.0030.04112.65
5.3.100.0100.03212.13
5.3.90.0080.03412.10
5.3.80.0050.03712.09
5.3.70.0080.03412.09
5.3.60.0080.03412.08
5.3.50.0030.03912.02
5.3.40.0070.03512.03
5.3.30.0060.03411.98
5.3.20.0060.03511.76
5.3.10.0070.03311.73
5.3.00.0050.03611.71
5.2.170.0040.0309.22
5.2.160.0040.0319.22
5.2.150.0030.0329.23
5.2.140.0040.0319.22
5.2.130.0050.0289.18
5.2.120.0050.0289.18
5.2.110.0040.0299.18
5.2.100.0070.0259.18
5.2.90.0070.0259.17
5.2.80.0050.0299.18
5.2.70.0070.0289.18
5.2.60.0050.0299.14
5.2.50.0060.0319.10
5.2.40.0060.0279.08
5.2.30.0050.0309.05
5.2.20.0040.0299.04
5.2.10.0040.0288.94
5.2.00.0040.0308.80
5.1.60.0040.0248.09
5.1.50.0040.0338.09
5.1.40.0050.0278.07
5.1.30.0060.0368.42
5.1.20.0100.0338.43
5.1.10.0040.0268.17
5.1.00.0030.0328.17
5.0.50.0060.0186.64
5.0.40.0040.0186.51
5.0.30.0050.0296.31
5.0.20.0060.0176.28
5.0.10.0030.0276.26
5.0.00.0020.0326.25
4.4.90.0020.0174.78
4.4.80.0040.0144.75
4.4.70.0020.0174.76
4.4.60.0020.0164.76
4.4.50.0020.0164.77
4.4.40.0060.0284.71
4.4.30.0050.0144.75
4.4.20.0030.0164.84
4.4.10.0040.0154.85
4.4.00.0040.0314.76
4.3.110.0020.0174.67
4.3.100.0030.0154.66
4.3.90.0030.0144.64
4.3.80.0050.0224.59
4.3.70.0040.0134.63
4.3.60.0030.0144.62
4.3.50.0040.0214.62
4.3.40.0040.0244.54
4.3.30.0040.0193.30
4.3.20.0020.0223.28
4.3.10.0020.0213.24
4.3.00.0030.0207.86

preferences:
46.94 ms | 401 KiB | 5 Q