Edit report at https://bugs.php.net/bug.php?id=64084&edit=1
ID: 64084 Updated by: ras...@php.net Reported by: narasius at gmail dot com Summary: Using exceptions is much slower than using function-approach -Status: Open +Status: Wont fix Type: Bug Package: Performance problem Operating System: Linux PHP Version: 5.4.11 Block user comment: N Private report: N New Comment: Yup, exceptions are not super fast. But assuming you are not using exceptions for flow-control and they only happen in really exceptional cases, it shouldn't be an issue. Previous Comments: ------------------------------------------------------------------------ [2013-01-27 12:17:42] narasius at gmail dot com 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 this bug report at https://bugs.php.net/bug.php?id=64084&edit=1