3v4l.org

run code in 300+ PHP versions simultaneously
<?php $start = microtime(true); $fn = @create_function('$a,$b', 'return log($a * $b);'); $v = 0; for ($i = 0; $i < 1000; $i++) $v += $fn($i, $i); echo("create_function: " . (microtime(true) - $start) . "\n"); $start = microtime(true); $v = 0; for ($i = 0; $i < 1000; $i++) $v += eval("return log($i * $i);"); echo("eval: " . (microtime(true) - $start) . "\n"); $start = microtime(true); $fn = fn($a, $b) => log($a * $b); $v = 0; for ($i = 0; $i < 1000; $i++) $v += $fn($i, $i); echo("arrow function: " . (microtime(true) - $start) . "\n"); $start = microtime(true); $fn = function ($a, $b) { return log($a * $b); }; $v = 0; for ($i = 0; $i < 1000; $i++) $v += $fn($i, $i); echo("anonymous function: " . (microtime(true) - $start) . "\n");
Output for 7.4.1
create_function: 0.00025701522827148 eval: 0.0032379627227783 arrow function: 0.00015091896057129 anonymous function: 0.00011515617370605
Output for 7.4.0
create_function: 0.00079011917114258 eval: 0.0031521320343018 arrow function: 0.00010991096496582 anonymous function: 9.9897384643555E-5
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.26, 7.3.0 - 7.3.13
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in /in/8euWR on line 17
Process exited with code 255.

preferences:
39.72 ms | 409 KiB | 5 Q