3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function xrange($start, $end, $step = 1) { while ($start <= $end) { yield $start; $start += $step; } } function reduce(Generator $iterator, Callable $callback, $initial = null) { $result = $initial; foreach($iterator as $value) { $result = $callback($result, $value); } return $result; } $start = microtime(true); reduce(xrange(1, 140000), function($r, $v) {return $r + $v;}, 0); $byGen = microtime(true) - $start; $start =microtime(true); array_reduce(range(1,140000), function($r, $v) {return $r + $v;}, 0); $byNormal = microtime(true) - $start; $percent = ($byGen - $byNormal)*100/$byNormal; printf("Generator is %s than normal function %.2f%%.\n", ($byGen > $byNormal ? 'Slower' : 'Faster'), abs($percent));
based on XFnjS
Output for 7.3.0
Generator is Faster than normal function 4.39%.
Output for 7.2.13
Generator is Slower than normal function 2.41%.
Output for 7.2.12
Generator is Slower than normal function 91.47%.
Output for 7.2.11
Generator is Faster than normal function 30.09%.
Output for 7.2.10
Generator is Faster than normal function 49.30%.
Output for 7.2.9
Generator is Slower than normal function 80.88%.
Output for 7.2.8
Generator is Slower than normal function 23.08%.
Output for 7.2.7
Generator is Slower than normal function 0.39%.
Output for 7.2.6
Generator is Slower than normal function 24.12%.
Output for 7.2.5
Generator is Slower than normal function 49.14%.
Output for 7.2.4
Generator is Slower than normal function 1.49%.
Output for 7.2.3
Generator is Faster than normal function 9.94%.
Output for 7.2.2
Generator is Faster than normal function 12.42%.
Output for 7.2.1
Generator is Faster than normal function 16.04%.
Output for 7.2.0
Generator is Slower than normal function 3.69%.
Output for 7.1.25
Generator is Slower than normal function 6.76%.
Output for 7.1.24
Generator is Slower than normal function 63.28%.
Output for 7.1.23
Generator is Slower than normal function 123.61%.
Output for 7.1.22
Generator is Slower than normal function 67.91%.
Output for 7.1.21
Generator is Faster than normal function 1.07%.
Output for 7.1.20
Generator is Slower than normal function 8.05%.
Output for 7.1.19
Generator is Slower than normal function 100.65%.
Output for 7.1.18
Generator is Slower than normal function 93.26%.
Output for 7.1.17
Generator is Slower than normal function 78.05%.
Output for 7.1.16
Generator is Slower than normal function 45.95%.
Output for 7.1.15
Generator is Slower than normal function 39.64%.
Output for 7.1.14
Generator is Slower than normal function 113.86%.
Output for 7.1.13
Generator is Slower than normal function 63.99%.
Output for 7.1.12
Generator is Slower than normal function 40.46%.
Output for 7.1.11
Generator is Slower than normal function 85.78%.
Output for 7.1.10
Generator is Slower than normal function 76.83%.
Output for 7.1.9
Generator is Slower than normal function 97.20%.
Output for 7.1.8
Generator is Slower than normal function 79.67%.
Output for 7.1.7
Generator is Slower than normal function 87.16%.
Output for 7.1.6
Generator is Slower than normal function 139.00%.
Output for 7.1.5
Generator is Slower than normal function 77.73%.
Output for 7.1.4
Generator is Slower than normal function 366.57%.
Output for 7.1.3
Generator is Slower than normal function 249.22%.
Output for 7.1.2
Generator is Slower than normal function 265.81%.
Output for 7.1.1
Generator is Slower than normal function 384.01%.
Output for 7.1.0
Generator is Slower than normal function 160.95%.
Output for 7.0.33
Generator is Slower than normal function 74.18%.
Output for 7.0.26
Generator is Slower than normal function 58.10%.
Output for 7.0.25
Generator is Slower than normal function 30.18%.
Output for 7.0.24
Generator is Slower than normal function 91.31%.
Output for 7.0.23
Generator is Slower than normal function 56.78%.
Output for 7.0.22
Generator is Slower than normal function 62.88%.
Output for 7.0.21
Generator is Slower than normal function 87.41%.
Output for 7.0.20
Generator is Slower than normal function 75.81%.
Output for 7.0.19
Generator is Slower than normal function 81.15%.
Output for 7.0.18
Generator is Slower than normal function 95.29%.
Output for 7.0.17
Generator is Slower than normal function 72.17%.
Output for 7.0.16
Generator is Slower than normal function 43.51%.
Output for 7.0.15
Generator is Slower than normal function 70.27%.
Output for 7.0.14
Generator is Slower than normal function 73.14%.
Output for 7.0.13
Generator is Slower than normal function 31.84%.
Output for 7.0.12
Generator is Slower than normal function 69.35%.
Output for 7.0.11
Generator is Slower than normal function 13.82%.
Output for 7.0.10
Generator is Slower than normal function 75.47%.
Output for 7.0.9
Generator is Slower than normal function 70.81%.
Output for 7.0.8
Generator is Slower than normal function 65.14%.
Output for 7.0.7
Generator is Slower than normal function 74.78%.
Output for 7.0.6
Generator is Faster than normal function 2.00%.
Output for 7.0.5
Generator is Slower than normal function 69.15%.
Output for 7.0.4
Generator is Slower than normal function 16.37%.
Output for 7.0.3
Generator is Slower than normal function 141.23%.
Output for 7.0.2
Generator is Slower than normal function 1.43%.
Output for 7.0.1
Generator is Slower than normal function 54.39%.
Output for 7.0.0
Generator is Slower than normal function 5.42%.
Output for hhvm-3.22.0
Generator is Slower than normal function 163.77%.
Output for hhvm-3.21.3
Generator is Slower than normal function 305.96%.
Output for hhvm-3.18.5
Generator is Slower than normal function 312.24%.
Output for 5.6.38
Generator is Slower than normal function 12.36%.
Output for 5.6.30
Generator is Faster than normal function 30.03%.
Output for 5.6.29
Generator is Slower than normal function 3.30%.
Output for 5.6.28
Generator is Faster than normal function 23.53%.
Output for 5.6.27
Generator is Faster than normal function 26.96%.
Output for 5.6.26
Generator is Faster than normal function 13.46%.
Output for 5.6.25
Generator is Faster than normal function 6.88%.
Output for 5.6.24
Generator is Faster than normal function 14.16%.
Output for 5.6.23
Generator is Faster than normal function 20.58%.
Output for 5.6.22
Generator is Slower than normal function 2.65%.
Output for 5.6.21
Generator is Faster than normal function 9.40%.
Output for 5.6.9, 5.6.20
Generator is Slower than normal function 25.33%.
Output for 5.6.19
Generator is Slower than normal function 20.73%.
Output for 5.6.18
Generator is Faster than normal function 22.46%.
Output for 5.6.17
Generator is Faster than normal function 29.56%.
Output for 5.6.16
Generator is Faster than normal function 39.25%.
Output for 5.6.15
Generator is Faster than normal function 26.34%.
Output for 5.6.14
Generator is Faster than normal function 9.91%.
Output for 5.6.13
Generator is Faster than normal function 58.01%.
Output for 5.6.12
Generator is Slower than normal function 17.23%.
Output for 5.6.11
Generator is Faster than normal function 40.15%.
Output for 5.6.10
Generator is Faster than normal function 10.19%.
Output for 5.6.8
Generator is Slower than normal function 3.20%.
Output for 5.6.7
Generator is Faster than normal function 17.91%.
Output for 5.6.6
Generator is Faster than normal function 16.27%.
Output for 5.6.5
Generator is Faster than normal function 40.87%.
Output for 5.6.4
Generator is Faster than normal function 17.37%.
Output for 5.6.3
Generator is Faster than normal function 14.33%.
Output for 5.6.2
Generator is Faster than normal function 16.50%.
Output for 5.6.1
Generator is Faster than normal function 31.97%.
Output for 5.6.0
Generator is Slower than normal function 19.01%.