<?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));
- Output for 7.4.8
- Generator is Slower than normal function 13.80%.
- Output for 7.4.7
- Generator is Slower than normal function 16.64%.
- Output for 7.4.6
- Generator is Slower than normal function 18.22%.
- Output for 7.4.5
- Generator is Slower than normal function 22.42%.
- Output for 7.4.4
- Generator is Slower than normal function 3.92%.
- Output for 7.4.3
- Generator is Slower than normal function 21.55%.
- Output for 7.4.2
- Generator is Slower than normal function 21.31%.
- Output for 7.4.1
- Generator is Faster than normal function 10.01%.
- Output for 7.4.0
- Generator is Slower than normal function 14.07%.
- Output for 7.3.20
- Generator is Slower than normal function 30.69%.
- Output for 7.3.19
- Generator is Slower than normal function 13.82%.
- Output for 7.3.18
- Generator is Slower than normal function 8.75%.
- Output for 7.3.17
- Generator is Slower than normal function 17.21%.
- Output for 7.3.16
- Generator is Slower than normal function 9.27%.
- Output for 7.3.15
- Generator is Faster than normal function 11.42%.
- Output for 7.3.14
- Generator is Slower than normal function 56.61%.
- Output for 7.3.13
- Generator is Slower than normal function 24.00%.
- Output for 7.3.12
- Generator is Slower than normal function 23.08%.
- Output for 7.3.11
- Generator is Faster than normal function 20.56%.
- Output for 7.3.10
- Generator is Slower than normal function 25.44%.
- Output for 7.3.9
- Generator is Slower than normal function 2.48%.
- Output for 7.3.8
- Generator is Faster than normal function 44.65%.
- Output for 7.3.7
- Generator is Slower than normal function 41.24%.
- Output for 7.3.6
- Generator is Faster than normal function 11.19%.
- Output for 7.3.5
- Generator is Slower than normal function 20.70%.
- Output for 7.3.4
- Generator is Slower than normal function 33.82%.
- Output for 7.3.3
- Generator is Slower than normal function 26.11%.
- Output for 7.3.2
- Generator is Slower than normal function 11.95%.
- Output for 7.3.1
- Generator is Slower than normal function 6.72%.
- Output for 7.3.0
- Generator is Slower than normal function 20.72%.
- Output for 7.2.32
- Generator is Slower than normal function 31.58%.
- Output for 7.2.31
- Generator is Slower than normal function 12.17%.
- Output for 7.2.30
- Generator is Slower than normal function 34.56%.
- Output for 7.2.29
- Generator is Slower than normal function 47.99%.
- Output for 7.2.28
- Generator is Slower than normal function 68.04%.
- Output for 7.2.27
- Generator is Slower than normal function 22.37%.
- Output for 7.2.26
- Generator is Slower than normal function 31.26%.
- Output for 7.2.25
- Generator is Faster than normal function 19.21%.
- Output for 7.2.24
- Generator is Slower than normal function 36.78%.
- Output for 7.2.23
- Generator is Slower than normal function 31.31%.
- Output for 7.2.22
- Generator is Slower than normal function 28.65%.
- Output for 7.2.21
- Generator is Slower than normal function 31.82%.
- Output for 7.2.20
- Generator is Slower than normal function 103.63%.
- Output for 7.2.19
- Generator is Faster than normal function 24.35%.
- Output for 7.2.18
- Generator is Faster than normal function 41.83%.
- Output for 7.2.17
- Generator is Slower than normal function 83.53%.
- Output for 7.2.16
- Generator is Slower than normal function 31.88%.
- Output for 7.2.15
- Generator is Faster than normal function 37.65%.
- Output for 7.2.14
- Generator is Slower than normal function 20.46%.
- Output for 7.2.13
- Generator is Faster than normal function 27.95%.
- Output for 7.2.12
- Generator is Slower than normal function 10.85%.
- Output for 7.2.11
- Generator is Faster than normal function 30.57%.
- Output for 7.2.10
- Generator is Slower than normal function 12.07%.
- Output for 7.2.9
- Generator is Faster than normal function 85.39%.
- Output for 7.2.8
- Generator is Slower than normal function 4.48%.
- Output for 7.2.7
- Generator is Slower than normal function 48.43%.
- Output for 7.2.6
- Generator is Faster than normal function 3.54%.
- Output for 7.2.5
- Generator is Slower than normal function 13.95%.
- Output for 7.2.4
- Generator is Faster than normal function 6.28%.
- Output for 7.2.3
- Generator is Slower than normal function 19.02%.
- Output for 7.2.2
- Generator is Slower than normal function 6.28%.
- Output for 7.2.1
- Generator is Slower than normal function 22.00%.
- Output for 7.2.0
- Generator is Slower than normal function 14.94%.
- Output for 7.1.33
- Generator is Faster than normal function 1.81%.
- Output for 7.1.32
- Generator is Slower than normal function 89.51%.
- Output for 7.1.31
- Generator is Slower than normal function 8.57%.
- Output for 7.1.30
- Generator is Slower than normal function 33.85%.
- Output for 7.1.29
- Generator is Faster than normal function 34.08%.
- Output for 7.1.28
- Generator is Faster than normal function 12.61%.
- Output for 7.1.27
- Generator is Slower than normal function 32.01%.
- Output for 7.1.26
- Generator is Slower than normal function 38.41%.
- Output for 7.1.25
- Generator is Slower than normal function 60.76%.
- Output for 7.1.24
- Generator is Slower than normal function 45.07%.
- Output for 7.1.23
- Generator is Faster than normal function 57.78%.
- Output for 7.1.22
- Generator is Slower than normal function 99.11%.
- Output for 7.1.21
- Generator is Faster than normal function 21.66%.
- Output for 7.1.20
- Generator is Slower than normal function 19.96%.
- Output for 7.1.19
- Generator is Slower than normal function 11.87%.
- Output for 7.1.18
- Generator is Slower than normal function 2.12%.
- Output for 7.1.17
- Generator is Faster than normal function 21.50%.
- Output for 7.1.16
- Generator is Faster than normal function 45.45%.
- Output for 7.1.15
- Generator is Slower than normal function 17.35%.
- Output for 7.1.14
- Generator is Slower than normal function 5.54%.
- Output for 7.1.13
- Generator is Slower than normal function 25.96%.
- Output for 7.1.12
- Generator is Faster than normal function 45.88%.
- Output for 7.1.11
- Generator is Slower than normal function 25.76%.
- Output for 7.1.10
- Generator is Faster than normal function 5.47%.
- Output for 7.1.9
- Generator is Slower than normal function 40.05%.
- Output for 7.1.8
- Generator is Slower than normal function 6.96%.
- Output for 7.1.7
- Generator is Slower than normal function 20.22%.
- Output for 7.1.6
- Generator is Slower than normal function 2.00%.
- Output for 7.1.5
- Generator is Slower than normal function 5.93%.
- Output for 7.1.4
- Generator is Faster than normal function 58.04%.
- Output for 7.1.3
- Generator is Slower than normal function 9.32%.
- Output for 7.1.2
- Generator is Slower than normal function 34.59%.
- Output for 7.1.1
- Generator is Faster than normal function 24.51%.
- Output for 7.1.0
- Generator is Slower than normal function 5.64%.
- Output for 7.0.33
- Generator is Slower than normal function 70.41%.
- Output for 7.0.32
- Generator is Slower than normal function 31.80%.
- Output for 7.0.31
- Generator is Slower than normal function 16.68%.
- Output for 7.0.30
- Generator is Faster than normal function 23.70%.
- Output for 7.0.29
- Generator is Slower than normal function 13.20%.
- Output for 7.0.28
- Generator is Slower than normal function 2.51%.
- Output for 7.0.27
- Generator is Faster than normal function 28.54%.
- Output for 7.0.26
- Generator is Slower than normal function 33.72%.
- Output for 7.0.25
- Generator is Slower than normal function 13.62%.
- Output for 7.0.24
- Generator is Slower than normal function 0.81%.
- Output for 7.0.23
- Generator is Faster than normal function 2.98%.
- Output for 7.0.22
- Generator is Slower than normal function 11.80%.
- Output for 7.0.21
- Generator is Faster than normal function 36.30%.
- Output for 7.0.20
- Generator is Slower than normal function 25.32%.
- Output for 7.0.19
- Generator is Slower than normal function 44.82%.
- Output for 7.0.18
- Generator is Slower than normal function 5.35%.
- Output for 7.0.17
- Generator is Slower than normal function 56.36%.
- Output for 7.0.16
- Generator is Slower than normal function 35.48%.
- Output for 7.0.15
- Generator is Slower than normal function 28.70%.
- Output for 7.0.14
- Generator is Slower than normal function 21.91%.
- Output for 7.0.13
- Generator is Slower than normal function 40.11%.
- Output for 7.0.12
- Generator is Faster than normal function 70.01%.
- Output for 7.0.11
- Generator is Slower than normal function 88.10%.
- Output for 7.0.10
- Generator is Slower than normal function 17.03%.
- Output for 7.0.9
- Generator is Slower than normal function 67.29%.
- Output for 7.0.8
- Generator is Slower than normal function 38.18%.
- Output for 7.0.7
- Generator is Slower than normal function 22.81%.
- Output for 7.0.6
- Generator is Faster than normal function 59.98%.
- Output for 7.0.5
- Generator is Slower than normal function 2.05%.
- Output for 7.0.4
- Generator is Slower than normal function 8.31%.
- Output for 7.0.3
- Generator is Faster than normal function 39.79%.
- Output for 7.0.2
- Generator is Faster than normal function 6.59%.
- Output for 7.0.1
- Generator is Faster than normal function 30.38%.
- Output for 7.0.0
- Generator is Faster than normal function 54.46%.
- Output for 5.6.40
- Generator is Faster than normal function 28.07%.
- Output for 5.6.39
- Generator is Faster than normal function 59.96%.
- Output for 5.6.38
- Generator is Slower than normal function 17.27%.
- Output for 5.6.37
- Generator is Faster than normal function 47.05%.
- Output for 5.6.36
- Generator is Faster than normal function 0.95%.
- Output for 5.6.35
- Generator is Faster than normal function 22.65%.
- Output for 5.6.34
- Generator is Faster than normal function 47.99%.
- Output for 5.6.33
- Generator is Faster than normal function 20.53%.
- Output for 5.6.32
- Generator is Faster than normal function 27.82%.
- Output for 5.6.31
- Generator is Faster than normal function 35.82%.
- Output for 5.6.30
- Generator is Faster than normal function 49.44%.
- Output for 5.6.29
- Generator is Faster than normal function 31.18%.
- Output for 5.6.28
- Generator is Faster than normal function 52.08%.
- Output for 5.6.27
- Generator is Faster than normal function 24.24%.
- Output for 5.6.26
- Generator is Faster than normal function 25.50%.
- Output for 5.6.25
- Generator is Faster than normal function 26.54%.
- Output for 5.6.24
- Generator is Faster than normal function 42.28%.
- Output for 5.6.23
- Generator is Faster than normal function 10.56%.
- Output for 5.6.22
- Generator is Faster than normal function 54.65%.
- Output for 5.6.21
- Generator is Faster than normal function 58.42%.
- Output for 5.6.20
- Generator is Faster than normal function 29.20%.
- Output for 5.6.19
- Generator is Faster than normal function 41.52%.
- Output for 5.6.18
- Generator is Faster than normal function 18.12%.
- Output for 5.6.17
- Generator is Faster than normal function 22.85%.
- Output for 5.6.16
- Generator is Faster than normal function 45.26%.
- Output for 5.6.15
- Generator is Faster than normal function 37.71%.
- Output for 5.6.14
- Generator is Faster than normal function 38.18%.
- Output for 5.6.13
- Generator is Faster than normal function 53.91%.
- Output for 5.6.12
- Generator is Faster than normal function 37.10%.
- Output for 5.6.11
- Generator is Faster than normal function 14.40%.
- Output for 5.6.10
- Generator is Slower than normal function 4.57%.
- Output for 5.6.9
- Generator is Faster than normal function 51.79%.
- Output for 5.6.8
- Generator is Faster than normal function 11.73%.
- Output for 5.6.7
- Generator is Faster than normal function 28.92%.
- Output for 5.6.6
- Generator is Faster than normal function 36.96%.
- Output for 5.6.5
- Generator is Faster than normal function 18.74%.
- Output for 5.6.4
- Generator is Faster than normal function 32.55%.
- Output for 5.6.3
- Generator is Faster than normal function 53.72%.
- Output for 5.6.2
- Generator is Faster than normal function 28.03%.
- Output for 5.6.1
- Generator is Faster than normal function 36.21%.
- Output for 5.6.0
- Generator is Faster than normal function 49.80%.
- Output for 5.5.38
- Generator is Faster than normal function 26.95%.
- Output for 5.5.37
- Generator is Faster than normal function 20.33%.
- Output for 5.5.36
- Generator is Faster than normal function 28.43%.
- Output for 5.5.35
- Generator is Faster than normal function 23.35%.
- Output for 5.5.34
- Generator is Faster than normal function 28.04%.
- Output for 5.5.33
- Generator is Faster than normal function 46.43%.
- Output for 5.5.32
- Generator is Faster than normal function 25.44%.
- Output for 5.5.31
- Generator is Faster than normal function 42.34%.
- Output for 5.5.30
- Generator is Faster than normal function 0.53%.
- Output for 5.5.29
- Generator is Faster than normal function 31.90%.
- Output for 5.5.28
- Generator is Faster than normal function 56.63%.
- Output for 5.5.27
- Generator is Faster than normal function 56.18%.
- Output for 5.5.26
- Generator is Faster than normal function 39.03%.
- Output for 5.5.25
- Generator is Faster than normal function 42.82%.
- Output for 5.5.24
- Generator is Faster than normal function 37.87%.
- Output for 5.5.23
- Generator is Faster than normal function 48.90%.
- Output for 5.5.22
- Generator is Faster than normal function 37.34%.
- Output for 5.5.21
- Generator is Faster than normal function 30.44%.
- Output for 5.5.20
- Generator is Faster than normal function 17.79%.
- Output for 5.5.19
- Generator is Faster than normal function 25.94%.
- Output for 5.5.18
- Generator is Faster than normal function 37.14%.
- Output for 5.5.17
- Generator is Faster than normal function 50.56%.
- Output for 5.5.16
- Generator is Faster than normal function 11.47%.
- Output for 5.5.15
- Generator is Faster than normal function 24.45%.
- Output for 5.5.14
- Generator is Faster than normal function 46.86%.
- Output for 5.5.13
- Generator is Faster than normal function 35.93%.
- Output for 5.5.12
- Generator is Faster than normal function 27.33%.
- Output for 5.5.11
- Generator is Faster than normal function 29.99%.
- Output for 5.5.10
- Generator is Faster than normal function 43.69%.
- Output for 5.5.9
- Generator is Faster than normal function 30.83%.
- Output for 5.5.8
- Generator is Faster than normal function 41.11%.
- Output for 5.5.7
- Generator is Slower than normal function 7.94%.
- Output for 5.5.6
- Generator is Faster than normal function 16.11%.
- Output for 5.5.5
- Generator is Slower than normal function 14.06%.
- Output for 5.5.4
- Generator is Faster than normal function 38.40%.
- Output for 5.5.3
- Generator is Faster than normal function 5.75%.
- Output for 5.5.2
- Generator is Faster than normal function 37.17%.
- Output for 5.5.1
- Generator is Faster than normal function 31.95%.
- Output for 5.5.0
- Generator is Faster than normal function 20.18%.
- Output for 5.4.0 - 5.4.45
- Parse error: syntax error, unexpected '$start' (T_VARIABLE) in /in/hQPpe on line 4
Process exited with code 255. - Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
- Parse error: syntax error, unexpected T_VARIABLE in /in/hQPpe on line 4
Process exited with code 255. - Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
- Parse error: parse error, unexpected T_VARIABLE in /in/hQPpe on line 4
Process exited with code 255. - Output for 4.3.2 - 4.3.4
- Parse error: parse error in /in/hQPpe on line 4
Process exited with code 255.
preferences:
70.44 ms | 713 KiB | 5 Q