Created
May 25, 2015 14:57
-
-
Save jmikola/d21a54dc25a041505eac to your computer and use it in GitHub Desktop.
Benchmarking PHP exception throws and backtrace generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ php bench.php | |
Throwing: 0.060640 | |
Assigning and throwing: 0.064791 | |
Assigning once and throwing: 0.011064 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo "Throwing: "; | |
$s = microtime(true); | |
for ($i = 0; $i < 100000; $i++) { | |
try { | |
throw new Exception; | |
} catch (Exception $_) {} | |
} | |
printf("%0.6f\n", (microtime(true) - $s)); | |
echo "Assigning and throwing: "; | |
$s = microtime(true); | |
for ($i = 0; $i < 100000; $i++) { | |
try { | |
$e = new Exception; | |
throw $e; | |
} catch (Exception $_) {} | |
} | |
printf("%0.6f\n", (microtime(true) - $s)); | |
echo "Assigning once and throwing: "; | |
$s = microtime(true); | |
$e = new Exception; | |
for ($i = 0; $i < 100000; $i++) { | |
try { | |
throw $e; | |
} catch (Exception $_) {} | |
} | |
printf("%0.6f\n", (microtime(true) - $s)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment