Created
October 24, 2019 10:23
-
-
Save zuzu/b01de1a47f88531ec28f69c877e25fcc to your computer and use it in GitHub Desktop.
PHP try-catch パフォーマンステスト
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
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