3v4l.org

run code in 300+ PHP versions simultaneously
<?php const TESTS_TO_RUN = 10; const NUMBERS_TO_SUM = 100000; function displayTabularData($itemList) { // Header $testAmounts = reset(reset($itemList)); printf("%11s", ' '); foreach($testAmounts as $key => $value) printf("[%10s]", $key); echo PHP_EOL; // Info foreach($itemList as $item) { $results = array_shift($item); $name = array_shift($item); printf("[%10s]", $name); foreach ($results as $key => $value) { printf("%.8f, ", $value); } echo PHP_EOL; } } function getRunningTime(callable $callback, $size) { $ts = microtime(); call_user_func($callback, $size); $time = microtime() - $ts; return $time; } function benchmarkCallback(callable $callback, $tests = TESTS_TO_RUN, $step = NUMBERS_TO_SUM) { $collection = []; for($size = $step; $size <= $tests * $step; $size += $step) { $collection[$size] = getRunningTime($callback, $size); } return $collection; } $imperative = function ($size) { for ($sum = 0, $i = 1; $i <= $size; $sum += $i, $i++); }; $functional = function ($size) { array_sum(range(1, $size)); }; displayTabularData([ [benchmarkCallback($imperative), 'Imperative'], [benchmarkCallback($functional), 'Functional'] ]);

This is an error 500

Value for `_results` contains invalid data `array`


preferences:
161.77 ms | 2286 KiB | 20 Q