From: narasius at gmail dot com Operating system: Linux PHP version: 5.4.11 Package: Performance problem Bug Type: Bug Bug description:Using exceptions is much slower than using function-approach
Description: ------------ In speed-sensible application this issue might affect the efficiancy. It appears that using an exception to report some error is at least 10 times slower (with recursion of 3) that using old-fashioned function-approach. For test-script below timing for using exception is 2.962 seconds, for using function-approach timing is 0.336 seconds. Test script: --------------- <?php function exceptionf1() { throw new Exception( 'msg' ) ; } function exceptionf2() { exceptionf1() ; } function exceptionf3() { exceptionf2() ; } function returnfunction1( &$error_msg ) { $error_msg = 'msg' ; return false ; } function returnfunction2( &$error_msg ) { return returnfunction1( $error_msg ) ; } function returnfunction3( &$error_msg ) { return returnfunction2( $error_msg ) ; } $t1 = microtime( true ) ; for ( $i = 0 ; $i < 1000000 ; $i++ ) { $success = true ; try { exceptionf3() ; } catch ( Exception $e ) { $success = false ; $error_msg = $e->getMessage() ; } } $d = microtime( true ) - $t1 ; print "d=$d\n" ; $t1 = microtime( true ) ; for ( $i = 0 ; $i < 1000000 ; $i++ ) { $success = returnfunction3( $error_msg ) ; } $d = microtime( true ) - $t1 ; print "d=$d\n" ; -- Edit bug report at https://bugs.php.net/bug.php?id=64084&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=64084&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=64084&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=64084&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=64084&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=64084&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=64084&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=64084&r=needscript Try newer version: https://bugs.php.net/fix.php?id=64084&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=64084&r=support Expected behavior: https://bugs.php.net/fix.php?id=64084&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=64084&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=64084&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=64084&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64084&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=64084&r=dst IIS Stability: https://bugs.php.net/fix.php?id=64084&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=64084&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=64084&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=64084&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=64084&r=mysqlcfg