3v4l.org

run code in 300+ PHP versions simultaneously
<?php function benchmark(callable ...$functions): void { $times = array_combine(array_keys($functions), array_fill(0, count($functions), 0.0)); $baseTime = 0.0; $baseCallable = fn() => null; $start = hrtime(true); $count = 0; while (hrtime(true) < $start + 1e9) { $startCall = hrtime(true); $baseCallable(); $baseTime += hrtime(true) - $startCall; foreach ($functions as $key => $function) { $startCall = hrtime(true); $function(); $times[$key] += hrtime(true) - $startCall; } $count++; } foreach ($times as $key => $time) { $times[$key] = $time - $baseTime; } if ($count < 100) { echo "Methods too low. Iterated only {$count} times\n"; } asort($times); echo "Benchmark results after {$count} iterations in nanoseconds:\n"; foreach ($times as $key => $time) { echo $key . ': ' . $time . "\n"; } } enum OptionEnum: string { case Option1 = 'opt1'; case Option2 = 'opt2'; case Option3 = 'opt3'; case Option4 = 'opt4'; case Option5 = 'opt5'; public static function values(): array { return ['opt1', 'opt2', 'opt3', 'opt4', 'opt5']; } public static function valuesArrayMap(): array { return array_map(static fn(self $c) => $c->value, self::cases()); } public static function valuesArrayColumn(): array { return array_column(self::cases(), 'value'); } } benchmark( arrayRaw: fn() => OptionEnum::values(), arrayMap: fn() => OptionEnum::valuesArrayMap(), arrayCol: fn() => OptionEnum::valuesArrayColumn(), );
Output for git.master_jit
Benchmark results after 1177549 iterations in nanoseconds: arrayRaw: 10983186 arrayCol: 162673721 arrayMap: 326444981
Output for git.master
Benchmark results after 1171213 iterations in nanoseconds: arrayRaw: 10801054 arrayCol: 162088255 arrayMap: 332194832

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
26.28 ms | 406 KiB | 5 Q