|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-01-19 11:28 UTC] gacek at intertele dot pl
Description: ------------ When playing with apd profiler, I have noticed huge cost of define() call. It's over 20x the cost of average count() call. Might it be apd inaccuracy or define() specifics, or define() implementation is heavily broken? PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 04:00:01 2025 UTC |
This is sample of "pprofp -u" output from fairly complex app: Total Elapsed Time = 2.47 Total System Time = 0.35 Total User Time = 1.36 Real User System secs/ cumm %Time (excl/cumm) (excl/cumm) (excl/cumm) Calls call s/call Memory Usage Name -------------------------------------------------------------------------------------- 13.9 0.24 0.24 0.19 0.19 0.04 0.04 850 0.0002 0.0002 0 define 12.1 0.27 0.27 0.16 0.16 0.05 0.05 18653 0.0000 0.0000 0 count 10.9 0.15 0.15 0.15 0.15 0.04 0.04 11652 0.0000 0.0000 0 is_array 9.1 0.26 0.26 0.12 0.12 0.03 0.03 15489 0.0000 0.0000 0 each 6.2 0.18 0.18 0.08 0.08 0.02 0.02 9012 0.0000 0.0000 0 array_shift 4.1 0.08 0.08 0.06 0.06 0.02 0.02 5402 0.0000 0.0000 0 ereg_replace 4.1 0.04 0.04 0.06 0.06 0.01 0.01 655 0.0001 0.0001 0 mysql_fetch_array 3.8 0.07 0.07 0.05 0.05 0.01 0.01 5277 0.0000 0.0000 0 urlencode 2.9 0.04 0.04 0.04 0.04 0.00 0.00 2520 0.0000 0.0000 0 func_num_args 2.9 0.05 0.05 0.04 0.04 0.00 0.00 1465 0.0000 0.0000 0 sprintfOK, comparison with count() was probably bad, but I will give you another example: I have declared 3 functions named myf1, myf2, myf3, which play with hash table. Not big one (10-20 elements), but processing is a bit complex. apd profiler shows following call tree of myf1(): myf1 func_num_args func_num_args func_get_args myf2 count array_shift is_array reset each each each count array_shift array_shift is_array reset each in_array each in_array each count array_shift is_array array_shift count array_shift is_array array_shift count myf3 each is_array each is_array each is_array each is_array count urlencode array_push count urlencode array_push count reset ksort each is_array ereg_replace ereg_replace ereg_replace ereg_replace urlencode urlencode array_push each join Each call of myf1() does nearly the same and operates on similiar hash. As you can see, above code envolves really complex operations as urlenconde'ing and ereg_replace'ing. Now, let's take a look at sample "pprofp -U" output. I have taken only relevant rows from it: Total Elapsed Time = 0.40 Total System Time = 0.04 Total User Time = 0.35 Real User System secs/ cumm %Time (excl/cumm) (excl/cumm) (excl/cumm) Calls call s/call Memory Usage Name -------------------------------------------------------------------------------------- 100.0 0.00 0.40 0.00 0.35 0.00 0.04 1 0.0000 0.3480 0 main 56.3 0.22 0.22 0.20 0.20 0.03 0.03 850 0.0002 0.0002 0 define 5.7 0.00 0.03 0.00 0.02 0.00 0.00 43 0.0000 0.0005 0 myf1 3.4 0.00 0.02 0.00 0.01 0.00 0.00 44 0.0000 0.0003 0 myf2 2.3 0.00 0.00 0.00 0.01 0.00 0.00 44 0.0000 0.0002 0 myf3 So, 850 calls of define() took cumulative 0.20s of user time from overall 0.35s (57%). 44 calls of complex myf1() took cumulatve 0.02s of user time (5.7%). It looks like average constant definition takes near half of operations from myf1() complex call tree 8-/. I would really classify "define" as too expensive.