3v4l.org

run code in 500+ 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(), );

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.5.70.0120.99816.64
8.5.60.0061.00416.86
8.5.50.0101.00616.71
8.5.30.0060.99618.13
8.5.20.0080.99220.20
8.5.10.0080.99516.86
8.5.00.0060.99923.09
8.4.220.0090.99519.81
8.4.210.0071.00119.66
8.4.180.0131.00119.83
8.4.170.0101.00423.95
8.4.160.0070.99923.23
8.4.150.0090.49916.88
8.4.140.0161.00617.30
8.4.130.0081.00517.55
8.4.90.0081.00617.93
8.3.310.0140.99318.59
8.3.300.0160.99620.91
8.3.290.0140.99620.87
8.3.280.0131.00118.55
8.3.270.0101.00116.55
8.3.260.0111.00016.69
8.3.180.0101.00116.63
8.3.50.0111.00018.37
8.2.300.0051.00820.54
8.1.340.0160.99523.57

preferences:
60.76 ms | 594 KiB | 5 Q