3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(E_ALL); function xrange($start, $end, $step = 1) { for ($i = $start; $i < $end; $i += $step) { yield $i; } } class RangeIterator implements Iterator { protected $start; protected $end; protected $step; protected $key; protected $value; public function __construct($start, $end, $step = 1) { $this->start = $start; $this->end = $end; $this->step = $step; } public function rewind() { $this->key = 0; $this->value = $this->start; } public function valid() { return $this->value < $this->end; } public function next() { $this->value += $this->step; $this->key += 1; } public function current() { return $this->value; } public function key() { return $this->key; } } function urange($start, $end, $step = 1) { $result = []; for ($i = $start; $i < $end; $i += $step) { $result[] = $i; } return $result; } function testTraversable($name, callable $traversableFactory) { $startTime = microtime(true); foreach ($traversableFactory() as $value) { // noop } echo $name, ' took ', microtime(true) - $startTime, ' seconds.', "\n"; } function testVariants($count) { testTraversable( "xrange ($count)", function() use($count) { return xrange(0, $count); } ); testTraversable( "RangeIterator ($count)", function() use($count) { return new RangeIterator(0, $count); } ); testTraversable( "urange ($count)", function() use($count) { return urange(0, $count); } ); testTraversable( "range ($count)", function() use($count) { return range(0, $count); } ); } testVariants(1000000); testVariants(10000); testVariants(100);

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)
7.4.00.0530.42647.94
7.3.120.0400.44347.90
7.3.110.0550.53147.70
7.3.100.0370.42647.91
7.3.90.0450.43847.68
7.3.80.0300.35648.00
7.3.70.0280.33247.73
7.3.60.0430.42747.73
7.3.50.0380.40947.66
7.3.40.0500.45047.68
7.3.30.0530.42747.84
7.3.20.0150.46350.46
7.3.10.0100.36050.73
7.3.00.0200.33750.61
7.2.250.0400.54648.14
7.2.240.0380.38548.01
7.2.230.0460.34747.77
7.2.220.0220.45348.14
7.2.210.0470.45148.08
7.2.200.0310.39147.99
7.2.190.0380.38448.07
7.2.180.0370.53548.00
7.2.170.0300.42248.21
7.2.00.2120.39453.15
7.1.330.0100.53649.73
7.1.320.0220.49649.89
7.1.310.0080.55649.78
7.1.300.0120.50749.78
7.1.290.0130.53049.66
7.1.280.0100.65949.73
7.1.270.0100.57549.54
7.1.260.0170.44149.63
7.1.70.0030.28050.84
7.1.60.0170.32751.11
7.1.50.0000.33651.22
7.1.00.0130.37356.19
7.0.202.1650.33948.99
7.0.140.0130.40755.99
7.0.120.0200.41055.96
7.0.60.0300.32052.99
7.0.50.0370.38750.80
7.0.40.0500.48049.52
7.0.30.0330.41749.56
7.0.20.0270.39349.55
7.0.10.0330.39049.59
7.0.00.0230.34349.54
5.6.280.0170.59785.76
5.6.210.0170.59785.42
5.6.200.0170.63382.81
5.6.190.0230.59782.90
5.6.180.0270.61082.81
5.6.170.0270.60782.80
5.6.160.0230.58082.79
5.6.150.0300.60082.85
5.6.140.0170.59382.90
5.6.130.0130.55082.66
5.6.120.0270.54082.80
5.6.110.0230.62082.80
5.6.100.0170.64782.79
5.6.90.0130.55782.64
5.6.80.0270.51782.14
5.6.70.0270.61382.27
5.6.60.0170.62382.14
5.6.50.0200.60382.14
5.6.40.0370.59382.16
5.6.30.0230.57782.11
5.6.20.0130.63382.21
5.6.10.0130.64082.16
5.6.00.0170.62382.18
5.5.350.0530.62785.10
5.5.340.0200.52782.59
5.5.330.0430.54382.70
5.5.320.0300.60782.61
5.5.310.0300.74082.56
5.5.300.0100.53382.65
5.5.290.0270.53382.56
5.5.280.0130.56082.58
5.5.270.0230.60382.65
5.5.260.0270.58382.65
5.5.250.0300.52782.47
5.5.240.0200.61381.99
5.5.230.0270.61381.98
5.5.220.0200.61381.96
5.5.210.0300.59781.81
5.5.200.0200.56381.96
5.5.190.0230.61381.80
5.5.180.0400.59781.97
5.5.160.0070.61781.96
5.5.150.0270.57781.80
5.5.140.0200.61382.01
5.5.130.0400.54381.93
5.5.120.0230.61081.93
5.5.110.0130.61081.95
5.5.100.0270.58781.88
5.5.90.0270.53381.83
5.5.80.0270.59781.95
5.5.70.0230.61381.85
5.5.60.0270.58081.82
5.5.50.0130.62081.95
5.5.40.0230.61781.86
5.5.30.0230.56381.68
5.5.20.0200.65081.86
5.5.10.0200.62781.86
5.5.00.0270.62381.84
5.4.450.0070.03719.43
5.4.440.0000.04319.32
5.4.430.0100.07719.38
5.4.420.0070.07019.37
5.4.410.0070.05319.18
5.4.400.0130.06719.10
5.4.390.0100.06319.14
5.4.380.0070.08019.10
5.4.370.0130.07319.05
5.4.360.0130.06019.12
5.4.350.0000.05318.88
5.4.340.0030.07019.09
5.4.320.0070.07719.05
5.4.310.0130.07019.00
5.4.300.0130.06719.02
5.4.290.0100.07719.03
5.4.280.0030.08019.04
5.4.270.0070.07319.10
5.4.260.0100.07318.89
5.4.250.0070.03719.06
5.4.240.0070.03719.09
5.4.230.0070.08019.01
5.4.220.0030.08319.11
5.4.210.0130.05319.06
5.4.200.0130.07019.09
5.4.190.0030.04019.04
5.4.180.0070.07718.94
5.4.170.0000.05319.26
5.4.160.0070.08318.96
5.4.150.0070.05719.04
5.4.140.0100.05716.43
5.4.130.0030.05016.30
5.4.120.0000.05716.43
5.4.110.0100.03716.37
5.4.100.0030.03716.48
5.4.90.0170.03716.59
5.4.80.0070.04716.46
5.4.70.0000.04316.46
5.4.60.0000.04016.41
5.4.50.0100.05316.35
5.4.40.0030.05016.45
5.4.30.0030.07716.33
5.4.20.0100.04716.32
5.4.10.0070.07716.38
5.4.00.0030.04315.74
5.3.290.0130.07014.71
5.3.280.0100.07014.63
5.3.270.0030.05314.66
5.3.260.0070.05014.60
5.3.250.0130.05314.63
5.3.240.0130.06714.81
5.3.230.0100.03314.61
5.3.220.0030.08014.78
5.3.210.0070.03714.66
5.3.200.0070.04014.77
5.3.190.0070.07714.64
5.3.180.0000.06314.56
5.3.170.0030.05314.59
5.3.160.0000.04014.51
5.3.150.0070.04714.62
5.3.140.0070.06314.52
5.3.130.0170.05714.59
5.3.120.0030.06314.57
5.3.110.0070.07714.64
5.3.100.0070.07313.99
5.3.90.0170.05314.23
5.3.80.0070.04014.11
5.3.70.0070.03314.02
5.3.60.0070.03313.89
5.3.50.0070.05013.85
5.3.40.0100.04314.05
5.3.30.0070.06713.99
5.3.20.0130.06013.73
5.3.10.0130.06713.68
5.3.00.0070.06713.68
5.2.170.0070.06011.16
5.2.160.0030.05311.20
5.2.150.0030.05711.16
5.2.140.0000.04011.18
5.2.130.0030.05311.10
5.2.120.0030.03311.21
5.2.110.0070.06011.32
5.2.100.0030.06311.09
5.2.90.0170.03311.11
5.2.80.0100.05311.09
5.2.70.0030.06311.10
5.2.60.0030.04011.01
5.2.50.0070.06011.04
5.2.40.0130.05310.98
5.2.30.0100.04710.88
5.2.20.0030.03011.17
5.2.10.0070.05710.81
5.2.00.0030.06010.81
5.1.60.0030.03710.21
5.1.50.0030.0579.92
5.1.40.0070.0379.95
5.1.30.0000.04010.34
5.1.20.0030.06310.42
5.1.10.0070.05010.29
5.1.00.0070.05010.07
5.0.50.0070.0438.39
5.0.40.0070.0278.50
5.0.30.0000.0478.25
5.0.20.0100.0308.25
5.0.10.0070.0308.25
5.0.00.0000.0438.25
4.4.90.0030.0378.25
4.4.80.0030.0138.25
4.4.70.0070.0178.25
4.4.60.0000.0378.25
4.4.50.0030.0338.25
4.4.40.0000.0578.25
4.4.30.0030.0378.25
4.4.20.0000.0378.25
4.4.10.0030.0308.25
4.4.00.0030.0438.25
4.3.110.0030.0338.25
4.3.100.0070.0278.25
4.3.90.0000.0378.25
4.3.80.0030.0578.25
4.3.70.0070.0378.25
4.3.60.0070.0338.25
4.3.50.0000.0378.25
4.3.40.0000.0538.25
4.3.30.0030.0308.25
4.3.20.0000.0278.25
4.3.10.0030.0208.25
4.3.00.0000.0378.25

preferences:
37.94 ms | 401 KiB | 5 Q