ID: 40165 User updated by: gacek at intertele dot pl Reported By: gacek at intertele dot pl -Status: Bogus +Status: Open Bug Type: Performance problem Operating System: Linux FC4 x86_64 PHP Version: 5.2.0 New Comment:
OK, 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. Previous Comments: ------------------------------------------------------------------------ [2007-01-19 14:19:12] [EMAIL PROTECTED] count(array()) just returns ht->nNumOfElements, this is probably the most simple function in PHP. define() copies (malloc() + memcpy()) the value, duplicates the name (malloc() + memcpy() again) and adds it to the hash of constants (which might involve realloc() etc.). So it's kinda expected that a function which does almost nothing is a bit faster, like 7x or 6x, which are the numbers I can see myself. ------------------------------------------------------------------------ [2007-01-19 11:33:51] [EMAIL PROTECTED] Not enough information was provided for us to be able to handle this bug. Please re-read the instructions at http://bugs.php.net/how-to-report.php If you can provide more information, feel free to add it to this bug and change the status back to "Open". Thank you for your interest in PHP. ------------------------------------------------------------------------ [2007-01-19 11:33:22] gacek at intertele dot pl 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 sprintf ------------------------------------------------------------------------ [2007-01-19 11:28:44] 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? ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=40165&edit=1