3v4l.org

run code in 300+ PHP versions simultaneously
<?php function benchmark(callable $fn, int $iterations = 1000000) { $start = microtime(true); for ($i = 0; $i < $iterations; $i++) { $fn(); } return microtime(true) - $start; } function benchmarks(array $benchmarks, int $iterations = 1000000) { $results = []; foreach ($benchmarks as $name => $callable) { $results[$name] = benchmark($callable, $iterations); } $maximum = max($results); $minimum = min($results); foreach ($results as $name => $result) { echo "$name: $result"; if ($result === $maximum) { echo ' (slowest)'; } if ($result === $minimum) { echo ' (fastest)'; } echo "\n"; } } $a = ['one' => 1, 'two' => 2, 'three' => 3]; benchmarks([ 'empty' => fn() => empty($a['none']), 'isset' => fn() => isset($a['none']), 'array_key_exists' => fn() => array_key_exists('none', $a), 'null comparison' => fn() => (bool)($a['none'] ?? false), ]);
Output for 7.4.9
empty: 0.064321994781494 isset: 0.055849075317383 (fastest) array_key_exists: 0.056078910827637 null comparison: 0.076056003570557 (slowest)
Output for 7.4.8
empty: 0.055670976638794 (fastest) isset: 0.056602954864502 array_key_exists: 0.059716939926147 null comparison: 0.071593999862671 (slowest)
Output for 7.4.7
empty: 0.054737091064453 isset: 0.053621053695679 (fastest) array_key_exists: 0.055931091308594 null comparison: 0.070784091949463 (slowest)
Output for 7.4.6
empty: 0.055747032165527 isset: 0.055401086807251 (fastest) array_key_exists: 0.055903911590576 null comparison: 0.072547912597656 (slowest)
Output for 7.4.5
empty: 0.057539939880371 (fastest) isset: 0.058264970779419 array_key_exists: 0.060813903808594 null comparison: 0.070713043212891 (slowest)
Output for 7.4.4
empty: 0.07237982749939 isset: 0.076083183288574 array_key_exists: 0.058097124099731 (fastest) null comparison: 0.078366041183472 (slowest)
Output for 7.4.3
empty: 0.059571981430054 isset: 0.055637836456299 (fastest) array_key_exists: 0.057744979858398 null comparison: 0.072932958602905 (slowest)
Output for 7.4.2
empty: 0.055749893188477 isset: 0.054594039916992 array_key_exists: 0.054030179977417 (fastest) null comparison: 0.070131063461304 (slowest)
Output for 7.4.1
empty: 0.054234027862549 isset: 0.054925918579102 array_key_exists: 0.05351185798645 (fastest) null comparison: 0.073632001876831 (slowest)
Output for 7.4.0
empty: 0.055773019790649 (fastest) isset: 0.059873104095459 array_key_exists: 0.05708384513855 null comparison: 0.071884870529175 (slowest)
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.21
Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ']' in /in/Y1ERg on line 37
Process exited with code 255.

preferences:
57.91 ms | 420 KiB | 5 Q