|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-01-02 19:58 UTC] public at syranide dot com
[2007-01-09 15:07 UTC] dmitry@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 07:00:01 2025 UTC |
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)