Skip to content

Instantly share code, notes, and snippets.

@tswicegood
Created June 1, 2009 23:35
Show Gist options
  • Save tswicegood/121879 to your computer and use it in GitHub Desktop.
Save tswicegood/121879 to your computer and use it in GitHub Desktop.
<?php
interface PackageException { }
class ConcretePackageException extends Exception implements PackageException { }
class MyException extends Exception { }
$total_looped = 10000;
echo "Throwing three different types of exceptions, ", number_format($total_looped), "\n";
$start = microtime(true);
for ($i = 0; $i < $total_looped; ++$i) {
try { throw new MyException(); } catch (Exception $e) {}
}
$time = microtime(true) - $start;
echo " MyException: ", $time, "\n",
" Time Per: ", ($time / $total_looped), "\n";
$start = microtime(true);
for ($i = 0; $i < $total_looped; ++$i) {
try { throw new ConcretePackageException(); } catch (Exception $e) {}
}
$time = microtime(true) - $start;
echo "ConcretePackageException: ", $time, "\n",
" Time Per: ", ($time / $total_looped), "\n";
$start = microtime(true);
for ($i = 0; $i < $total_looped; ++$i) {
try { throw new Exception(); } catch (Exception $e) {}
}
$time = microtime(true) - $start;
echo " Exception: ", $time, "\n",
" Time Per: ", ($time / $total_looped), "\n";
?>
// output from run:
Throwing three different types of exceptions, 10,000
MyException: 0.034233093261719
Time Per: 3.4233093261719E-6
ConcretePackageException: 0.033795833587646
Time Per: 3.3795833587646E-6
Exception: 0.030992984771729
Time Per: 3.0992984771729E-6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment