<?php $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('append', function () { $arr = []; for ($i = 0; $i < 1_000; $i++) { $arr[] = 'x'; } }); $benchFx('array_push', function () { $arr = []; for ($i = 0; $i < 1_000; $i++) { array_push($arr, 'x'); } }); $benchFx('array_unshift', function () { $arr = []; for ($i = 0; $i < 1_000; $i++) { array_unshift($arr, 'x'); } });
You have javascript disabled. You will not be able to edit any code.