3v4l.org

run code in 300+ PHP versions simultaneously
<?php function timeFunc($function, $runs) { $start = microtime(true); for ($i = 0; $i < $runs; $i++) { call_user_func($function); } return (microtime(true) - $start); } function Method1() { $foo = 'some words'; for ($i = 0; $i < 10000; $i++) { $t = "these are $foo"; } } function Method2() { $foo = 'some words'; for ($i = 0; $i < 10000; $i++) { $t = "these are {$foo}"; } } function Method3() { $foo = 'some words'; for ($i = 0; $i < 10000; $i++) { $t = "these are " . $foo; } } $a = timeFunc('Method1', 10); $b = timeFunc('Method2', 10); $c = timeFunc('Method3', 10); echo ($a + $b) / (2 * $a) . "\n"; echo ($a + $c) / (2 * $a) . "\n";

preferences:
39.65 ms | 402 KiB | 5 Q