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.1.70.0040.01917.22
7.1.60.0120.01619.82
7.1.50.0030.02416.71
7.1.00.0000.08322.37
7.0.200.0040.00816.79
7.0.140.0100.07322.08
7.0.100.0100.06020.34
7.0.90.0130.08020.22
7.0.80.0130.07020.18
7.0.70.0030.06020.28
7.0.60.0130.07720.27
7.0.50.0170.07720.67
7.0.40.0100.08720.14
7.0.30.0100.09020.09
7.0.20.0100.09720.05
7.0.10.0100.07020.09
7.0.00.0100.07720.04
5.6.280.0100.10722.29
5.6.250.0200.07722.00
5.6.240.0200.08321.99
5.6.230.0170.08721.98
5.6.220.0070.09721.98
5.6.210.0070.07721.93
5.6.200.0100.08022.42
5.6.190.0170.08022.34
5.6.180.0030.09022.45
5.6.170.0130.09022.38
5.6.160.0070.09322.42
5.6.150.0170.08022.32
5.6.140.0130.09022.35
5.6.130.0200.09322.27
5.6.120.0070.11022.42
5.6.110.0200.08022.32
5.6.100.0170.08322.38
5.6.90.0030.08722.43
5.6.80.0170.06321.70
5.6.70.0000.08321.62
5.6.60.0200.04021.76
5.6.50.0100.07321.83
5.6.40.0130.08721.70
5.6.30.0030.05321.76
5.6.20.0170.08321.70
5.6.10.0200.05321.61
5.6.00.0130.08021.66
5.5.380.0070.10021.72
5.5.370.0130.06721.76
5.5.360.0070.04721.69
5.5.350.0170.08321.75
5.5.340.0130.08022.09
5.5.330.0100.09322.04
5.5.320.0130.09022.14
5.5.310.0100.08322.16
5.5.300.0100.06722.24
5.5.290.0030.09322.11
5.5.280.0130.09022.11
5.5.270.0070.09322.18
5.5.260.0070.08722.21
5.5.250.0130.06321.98
5.5.240.0100.08721.52
5.5.230.0030.09721.50
5.5.220.0030.06321.52
5.5.210.0100.10021.61
5.5.200.0130.08021.40
5.5.190.0030.05721.59
5.5.180.0170.08721.30
5.5.160.0030.08321.54
5.5.150.0030.05021.54
5.5.140.0100.08721.54
5.5.130.0130.08021.53
5.5.120.0130.05321.52
5.5.110.0030.10021.57
5.5.100.0170.07021.46
5.5.90.0070.05321.38
5.5.80.0130.08321.44
5.5.70.0070.09021.47
5.5.60.0070.07321.31
5.5.50.0130.05021.37
5.5.40.0130.08021.39
5.5.30.0070.05721.38
5.5.20.0070.10021.23
5.5.10.0100.08021.29
5.5.00.0000.05721.28
5.4.450.0100.06319.37
5.4.440.0030.08319.24
5.4.430.0170.06719.52
5.4.420.0170.07319.53
5.4.410.0100.07319.02
5.4.400.0000.06719.21
5.4.390.0030.05019.05
5.4.380.0070.07319.03
5.4.370.0070.05719.18
5.4.360.0130.07318.85
5.4.350.0070.05319.14
5.4.340.0070.08318.88
5.4.320.0130.07019.05
5.4.310.0000.04718.85
5.4.300.0100.07019.18
5.4.290.0070.07718.90
5.4.280.0100.05319.04
5.4.270.0000.07319.18
5.4.260.0100.07719.18
5.4.250.0100.06318.90
5.4.240.0130.06719.02
5.4.230.0100.07319.16
5.4.220.0070.08719.04
5.4.210.0030.05318.94
5.4.200.0200.03019.08
5.4.190.0030.06018.94
5.4.180.0100.07319.15
5.4.170.0170.06319.12
5.4.160.0170.03719.02
5.4.150.0070.07719.14
5.4.140.0000.08316.37
5.4.130.0200.05716.39
5.4.120.0130.06316.35
5.4.110.0030.08016.50
5.4.100.0030.04716.48
5.4.90.0030.06716.34
5.4.80.0100.07016.49
5.4.70.0030.06716.49
5.4.60.0070.03316.45
5.4.50.0100.07016.41
5.4.40.0070.06316.37
5.4.30.0030.07716.48
5.4.20.0100.06716.47
5.4.10.0030.03716.24
5.4.00.0000.07015.85
5.3.290.0070.08014.74
5.3.280.0030.04014.68
5.3.270.0130.05014.59
5.3.260.0100.07014.56
5.3.250.0070.06014.60
5.3.240.0170.06314.68
5.3.230.0070.07714.63
5.3.220.0000.08014.62
5.3.210.0000.08714.63
5.3.200.0100.07314.63
5.3.190.0130.03014.61
5.3.180.0030.07314.62
5.3.170.0030.05014.63
5.3.160.0070.07714.62
5.3.150.0030.07314.63
5.3.140.0000.08314.66
5.3.130.0070.07314.53
5.3.120.0070.07314.48
5.3.110.0030.05014.54
5.3.100.0130.07014.09
5.3.90.0100.03714.01
5.3.80.0030.04314.16
5.3.70.0070.06313.95
5.3.60.0100.03714.09
5.3.50.0000.06313.85
5.3.40.0030.04314.05
5.3.30.0030.05313.89
5.3.20.0100.05313.71
5.3.10.0030.06713.65
5.3.00.0070.08313.62
5.2.170.0000.05011.15
5.2.160.0130.04311.19
5.2.150.0030.06711.16
5.2.140.0000.06311.02
5.2.130.0000.05711.16
5.2.120.0070.05310.96
5.2.110.0030.06711.15
5.2.100.0030.06310.95
5.2.90.0100.06010.96
5.2.80.0030.06311.00
5.2.70.0070.06011.17
5.2.60.0000.05711.16
5.2.50.0000.06711.12
5.2.40.0030.06310.88
5.2.30.0070.03310.83
5.2.20.0000.03310.91
5.2.10.0000.06710.97
5.2.00.0030.06010.86
5.1.60.0030.05010.38
5.1.50.0070.02310.38
5.1.40.0070.03010.38
5.1.30.0000.04010.38
5.1.20.0100.04010.41
5.1.10.0100.05010.38
5.1.00.0000.05010.38
5.0.50.0070.04010.38
5.0.40.0070.02710.38
5.0.30.0030.03310.38
5.0.20.0030.02710.38
5.0.10.0030.03310.38
5.0.00.0030.06010.38
4.4.90.0000.04010.38
4.4.80.0030.03010.38
4.4.70.0070.03310.38
4.4.60.0030.03310.38
4.4.50.0000.02710.38
4.4.40.0030.05010.38
4.4.30.0000.03310.38
4.4.20.0030.03010.38
4.4.10.0070.03310.38
4.4.00.0000.05310.38
4.3.110.0030.03310.38
4.3.100.0000.01710.38
4.3.90.0070.02010.38
4.3.80.0030.04010.38
4.3.70.0030.03310.38
4.3.60.0000.02310.38
4.3.50.0000.03310.38
4.3.40.0000.05010.38
4.3.30.0030.02710.38
4.3.20.0000.02310.38
4.3.10.0030.03010.38
4.3.00.0000.03310.38

preferences:
29.43 ms | 401 KiB | 5 Q