- Output for 8.2.11
- Result object : 0.063032150268555s Exceptions : 0.24891805648804s
- Output for 8.1.7
- Result object : 0.082381963729858s Exceptions : 0.48031616210938s
<?php
$iterations = 1_000_000;
class Result {
}
benchmark('Result object', fn() => new Result());
benchmark('Exceptions', fn() => throw new \RuntimeException());
function benchmark(string $label, \Closure $closure) {
global $iterations;
$sT = microtime(true);
for ($i = 0; $i < $iterations; $i ++) {
try {
$closure();
} catch (\Exception $e) {
}
}
echo $label . ' : ' . (microtime(true) - $sT) . 's' . PHP_EOL;
}