3v4l.org

run code in 300+ PHP versions simultaneously
<?php function acceptOne($a) {}; final class Foo { public $notTyped; public int $typed; } $benchFx = function (string $msg, \Closure $fx) { $times = []; for ($i = 0; $i < 10; $i++) { $t = microtime(true); $fx(); $t = microtime(true) - $t; $times[] = $t; } $bestTime = min($times); echo $msg . ': ' . round($bestTime * 1000, 2) . " ms\n"; }; $benchFx('assign not typed', function () { $foo = new Foo(); for ($i = 0; $i < 100_000; $i++) { $foo->notTyped = $i; $foo->notTyped = $i; $foo->notTyped = $i; $foo->notTyped = $i; $foo->notTyped = $i; } acceptOne($foo); }); $benchFx('assign typed', function () { $foo = new Foo(); for ($i = 0; $i < 100_000; $i++) { $foo->typed = $i; $foo->typed = $i; $foo->typed = $i; $foo->typed = $i; $foo->typed = $i; } acceptOne($foo); });

preferences:
33.38 ms | 406 KiB | 5 Q