#40002 [NEW]: Try/Catch performs poorly
| From: | public at syranide dot com | Date: | Tue, 02 Jan 2007 19:47:15 +0000 |
| Subject: | #40002 [NEW]: Try/Catch performs poorly | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-107107@lists.php.net to get a copy of this message | ||
From: public at syranide dot com
Operating system: Windows XP 32bit
PHP version: 5.2.0
PHP Bug Type: Performance problem
Bug description: Try/Catch performs poorly
Description:
------------
Try/Catch-statements in PHP is performing rather poorly, main problem that
seems to be that the Catch-clauses are always tried regardless of an
exception being thrown or not.
Although Try/Catch is pretty expensive (about twice of @), the worst part
is that it scales linear with each Catch.
Of course that might be very hard to not do and is not a problem, but the
problem arises from the linear scaling followed by Catch-clauses always
impacting performance, regardless of an Exception being thrown or not.
Reproduce code:
---------------
$start = microtime(TRUE);
class PHPException extends Exception {}
for($i = 0; $i < 100000; $i++) {
try {}
catch(PHPException $e) {}
catch(PHPException $e) {}
catch(PHPException $e) {}
catch(PHPException $e) {}
catch(PHPException $e) {}
}
echo microtime(TRUE) - $start;
Expected result:
----------------
Note that the above code is rather strupid in nature, but the result is
the same regardless.
From the above I would expect very similar performance to having only one
Catch-clause (or to be more precise, that in the event of no exception
being thrown performance is not linear to the number of Catch-clauses).
Actual result:
--------------
(nothing useful)
--
Edit bug report at http://bugs.php.net/?id=40002&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=40002&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=40002&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=40002&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=40002&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=40002&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=40002&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=40002&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=40002&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=40002&r=support
Expected behavior: http://bugs.php.net/fix.php?id=40002&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=40002&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=40002&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=40002&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=40002&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=40002&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=40002&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=40002&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=40002&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=40002&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=40002&r=mysqlcfg