Skip to content

Instantly share code, notes, and snippets.

@zuzu
Created October 24, 2019 10:23
Show Gist options
  • Save zuzu/b01de1a47f88531ec28f69c877e25fcc to your computer and use it in GitHub Desktop.
Save zuzu/b01de1a47f88531ec28f69c877e25fcc to your computer and use it in GitHub Desktop.
PHP try-catch パフォーマンステスト
try-catch non Exception
<?php
$time = microtime(TRUE);
$arr = array();
foreach (range(1, 1000000) as $i) {
try {
$arr[$i] = $i;
// throw new Exception("foo");
} catch (Exception $e) {
}
}
$ms = round((microtime(TRUE) - $time) * 1000);
print_r(array('microtime' => $ms));
?>
<br />
try-catch throw new Exception
<?php
$time = microtime(TRUE);
$arr = array();
foreach (range(1, 1000000) as $i) {
try {
$arr[$i] = $i;
throw new Exception("foo");
} catch (Exception $e) {
}
}
$ms = round((microtime(TRUE) - $time) * 1000);
print_r(array('microtime' => $ms));
?>
<br />
non try-catch
<?php
$time = microtime(TRUE);
$arr = array();
foreach (range(1, 1000000) as $i) {
$arr[$i] = $i;
}
$ms = round((microtime(TRUE) - $time) * 1000);
print_r(array('microtime' => $ms));
?>
<br />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment