Re: [SMARTY-DEV] Suggestion for the outputfilter.trimwhitespace.php plugin

From: Date: Sat, 03 Jan 2004 06:17:00 +0000
Subject: Re: [SMARTY-DEV] Suggestion for the outputfilter.trimwhitespace.php plugin
References: 1 2 3  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-2017@lists.php.net to get a copy of this message
On Friday 02 January 2004 11:56 pm, Bharat Mediratta wrote: > Hi, Gerard. This is a pure optimization, right? In those cases, > it'd be useful if you'd include some benchmark code and some simple > performance results so that we'd get an idea the performance gain. > Typically, optimizing a decent algorithm leads to less maintainable > code so it's nice for the maintainers to see exactly what they're > getting for the cost. > Yes its a pure optimization. As far as a benchmark, I currently use APD to profile my code, so these tests are actual page loads, which Im using multple calls of fetch() and display(). Im passing the "-l" switch to pprofp to show the number of times a function was used. Without the patch -------------------- Real User System secs/ cumm %Time (excl/cumm) (excl/cumm) (excl/cumm) Calls call s/call Memory Usage Name -------------------------------------------------------------------------------------- 0.0 0.01 0.01 0.00 0.00 0.00 0.00 68 0.0000 0.0000 1344 is_file 3.4 0.02 0.02 0.01 0.01 0.00 0.00 64 0.0000 0.0000 2024 count 3.4 0.00 0.00 0.01 0.01 0.00 0.00 59 0.0000 0.0000 10904 explode 0.0 0.00 0.06 0.00 0.06 0.00 0.00 56 0.0000 0.0000 576 mpn2_registry->getentry 3.4 0.02 0.02 0.01 0.01 0.00 0.00 56 0.0000 0.0000 6256 mpn2_registry->isentry 0.0 0.01 0.01 0.00 0.00 0.00 0.00 48 0.0000 0.0000 17192 define 0.0 0.00 0.00 0.00 0.00 0.00 0.00 43 0.0000 0.0000 120984 preg_replace 0.0 0.02 0.02 0.00 0.00 0.00 0.00 40 0.0000 0.0000 -1552 mpn2_language->getlang 0.0 0.00 0.00 0.00 0.00 0.00 0.00 35 0.0000 0.0000 96 is_string 6.9 0.01 0.21 0.02 0.16 0.00 0.04 35 0.0000 0.0000 9056 include 3.4 0.00 0.00 0.01 0.01 0.00 0.00 33 0.0000 0.0000 -8472 is_array 0.0 0.00 0.00 0.00 0.00 0.00 0.00 31 0.0000 0.0000 -54400 preg_match_all 0.0 0.00 0.00 0.00 0.00 0.00 0.00 31 0.0000 0.0000 25480 error_reporting 0.0 0.01 0.01 0.00 0.00 0.00 0.00 31 0.0000 0.0000 -49456 strlen 3.4 0.00 0.01 0.00 0.00 0.01 0.01 30 0.0000 0.0000 -42080 smarty_outputfilter_trimwhitespace_replace 0.0 0.00 0.00 0.00 0.00 0.00 0.00 25 0.0000 0.0000 1168 substr 0.0 0.00 0.00 0.00 0.00 0.00 0.00 24 0.0000 0.0000 5320 mysql_fetch_array 0.0 0.01 0.01 0.00 0.00 0.00 0.00 24 0.0000 0.0000 856 is_readable 6.9 0.01 0.01 0.01 0.01 0.01 0.01 23 0.0000 0.0000 38592 preg_match 0.0 0.00 0.00 0.00 0.01 0.00 0.00 23 0.0000 0.0000 192 mpn2_user->canaccess With the patch ---------------- Real User System secs/ cumm %Time (excl/cumm) (excl/cumm) (excl/cumm) Calls call s/call Memory Usage Name -------------------------------------------------------------------------------------- 6.9 0.02 0.02 0.01 0.01 0.01 0.01 68 0.0000 0.0000 1376 is_file 3.4 0.00 0.00 0.01 0.01 0.00 0.00 59 0.0000 0.0000 10928 explode 3.4 0.01 0.01 0.00 0.00 0.01 0.01 56 0.0000 0.0000 6176 mpn2_registry->isentry 0.0 0.00 0.06 0.00 0.05 0.00 0.01 56 0.0000 0.0000 560 mpn2_registry->getentry 0.0 0.01 0.01 0.00 0.00 0.00 0.00 48 0.0000 0.0000 17192 define 0.0 0.02 0.02 0.00 0.00 0.00 0.00 43 0.0000 0.0000 120992 preg_replace 3.4 0.00 0.00 0.00 0.00 0.01 0.01 40 0.0000 0.0000 -1560 mpn2_language->getlang 3.4 0.00 0.00 0.01 0.01 0.00 0.00 36 0.0000 0.0000 1600 count 0.0 0.00 0.00 0.00 0.00 0.00 0.00 35 0.0000 0.0000 96 is_string 0.0 0.00 0.21 0.00 0.17 0.00 0.02 35 0.0000 0.0000 9040 include 0.0 0.00 0.00 0.00 0.00 0.00 0.00 33 0.0000 0.0000 -8488 is_array 3.4 0.00 0.00 0.01 0.01 0.00 0.00 31 0.0000 0.0000 -54392 preg_match_all 0.0 0.00 0.00 0.00 0.00 0.00 0.00 31 0.0000 0.0000 25480 error_reporting 0.0 0.01 0.01 0.00 0.00 0.00 0.00 30 0.0000 0.0000 -59536 smarty_outputfilter_trimwhitespace_replace 0.0 0.00 0.00 0.00 0.00 0.00 0.00 25 0.0000 0.0000 1168 substr 0.0 0.00 0.00 0.00 0.00 0.00 0.00 24 0.0000 0.0000 832 is_readable 0.0 0.00 0.00 0.00 0.00 0.00 0.00 24 0.0000 0.0000 5312 mysql_fetch_array 0.0 0.01 0.01 0.00 0.00 0.00 0.00 23 0.0000 0.0000 1680 array_intersect 0.0 0.02 0.02 0.00 0.00 0.00 0.00 23 0.0000 0.0000 38584 preg_match 3.4 0.00 0.01 0.01 0.01 0.00 0.00 23 0.0000 0.0000 184 mpn2_user->canaccess As you can see "smarty_outputfilter_trimwhitespace_replace" is being called 30 times on the simplest "full window" (not a popup) page. Without the patch, count() was called 64 times, and strlen() was called 31 times. And what the profiling doesn't show is the number of times for() was called, but a best guess would be 31, the same number of times that strlen() was called. With the patch, the number of calls to count() dropped to 36, and strlen() wasn't included in the report, so its probably less than 23 times. That would also translate to less calls to the for() function also. What the patch basically does, is to make the smarty_outputfilter_trimwhitespace_replace() function only operate on <pre> <script> and <textarea> content, as the regex takes care of the rest. Hope this little read was beneficial....

« previous php.smarty.dev (#2017) next »