Substituting your favourite function for strlen() will probably not yield 
similar results, though.  strlen()'s implementation takes virtually no time.

Also, try defining gstrlen() before you use it.  It'd be much faster.

At 05:58 09-09-01, George Schlossnagle wrote:
>Benchmarking the execution time for a single function call by making a 
>page and request it via b is a pretty flawed method.  While it may show 
>that a single aliased call to gettext() doesn't change the execution time 
>of a script by much, it does not say anything about the relative times for 
>execution of a specific function.  You should call the function in  a type 
>loop and average over many executions.  Here's a sample you can try:
>
>strlen.php:
><?
>         $a = 'blah';
>         while($i < 100000) {
>                 $b = strlen($a);
>                 $i++;
>         }
>?>
>
>gstrlen.php:
><?
>         $a = 'blah';
>         while($i < 100000) {
>                 $b = gstrlen($a);
>                 $i++;
>         }
>         function gstrlen($str) {
>                 return strlen($str);
>         }
>?>
>
>
>22:54:00(george@wasabi)[~/src/php-4.0.6/ext]> time php 
>/opt/apache/htdocs/strlen.php
>X-Powered-By: PHP/4.0.6
>Content-type: text/html
>
>0.840u 0.010s 0:00.85 100.0%    0+0k 0+0io 293pf+0w
>
>22:54:17(george@wasabi)[~/src/php-4.0.6/ext]> time php 
>/opt/apache/htdocs/gstrlen.php
>X-Powered-By: PHP/4.0.6
>Content-type: text/html
>
>1.950u 0.010s 0:01.95 100.5%    0+0k 0+0io 295pf+0w
>
>When done often enough, the difference between calling userland functions 
>and builtins is _huge_.  Substitute your favorite function in for strlen 
>(I tried a bunch), you'll get similair results.  Having to switch executor 
>contexts evertime you call a userland function is really expensive.
>
>George
>
>
>
>
>On Saturday, September 8, 2001, at 08:07 PM, Cristopher Daniluk wrote:
>
>>I feel like you're getting a bit personal here, but I'll refrain from doing
>>the same and simply provide numbers. This is a demonstration to prove purely
>>the overhead of going into a userspace function that calls an internal
>>versus calling the internal directly. Obviously this isn't scientific, but
>>that's not my goal.
>>
>>3 scripts were created. First called _(""). Second defined a function as
>>follows:
>>
>>function b($str) { return gettext($str); }
>>
>>Third b("") instead of _("") - note the second one was created just to try
>>and normalize out any deviance from parsing the new function.
>>
>>Apache Bench was run at 1000 queries to give enough performance to
>>illustrate a significant deviance. A concurrency of 10 and 100 were used.
>>Each set was run 3 times and averages were taken to normalize outside
>>factors. Tests were run randomly at various times throughout the last hour,
>>to reduce the effect of foreign elements.
>>
>>First Test (using _)
>>Concurrency 10: 50.24/50.23/57.43 = 52.63
>>Concurrency 100: 44.58/46.59/44.53 = 46.23
>>
>>Second Test (defining b)
>>Concurrency 10: 55.05/56.19/50.55 = 53.93
>>Concurrency 100: 45.65/47.06/45.71 = 46.12
>>
>>Third Test (using b)
>>Concurrency 10: 55.16/55.82/52.16 = 54.38
>>Concurrency 100: 46.74/46.39/47.19 = 46.77
>>
>>I really truly and with all my heart believe that if simply calling a user
>>created function could drop performance by 25%, PHP would not be a viable
>>language. Whether my results are accurate findings or not, Rasmus's
>>demonstration of a 26.3% performance decrease by CALLING A FUNCTION is a lot
>>to swallow!
>>
>>Oh, and I'll refrain from making the muse that the latter test was faster.
>>
>>Having the user make their own function may not be the right solution for
>>this problem, but its phenomenally silly to argue that it would have a large
>>performance impact!
>>
>>Regards,
>>
>>
>>Cristopher Daniluk
>>President & CEO
>>email: [EMAIL PROTECTED]
>>direct: 330/530-2373
>>
>>Digital Services Network, Inc
>>Unleashing Your Potential
>>voice: 800/845-4822
>>web: http://www.dsnet.net/
>>
>>
>>-----Original Message-----
>>From: Chuck Hagenbuch [mailto:[EMAIL PROTECTED]]
>>Sent: Saturday, September 08, 2001 7:23 PM
>>To: [EMAIL PROTECTED]
>>Cc: 'PHP Developer List'
>>Subject: RE: [PHP-DEV] Woah
>>
>>
>>Quoting Cristopher Daniluk <[EMAIL PROTECTED]>:
>>
>>>Agreed, but is the speed loss really worth crying about?
>>
>>Obviously not to you, but I'm pretty sure you came down in the category of
>>people who'd never used gettext.
>>
>>>It is negligible calling a userspace function versus an internal compared
>>to
>>>the greater work that the typical PHP script does.
>>
>>What authority do you have to make this statement? Rasmus posted numbers.
>>Where
>>are yours?
>>
>>-chuck
>>
>>--
>>Charles Hagenbuch, <[EMAIL PROTECTED]>
>>Some fallen angels have their good reasons.
>>
>>--
>>PHP Development Mailing List <http://www.php.net/>
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>>To contact the list administrators, e-mail: [EMAIL PROTECTED]
><Attachment missing>> --
>>PHP Development Mailing List <http://www.php.net/>
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>>To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>
>Benchmarking the execution time for a single function call by making a 
>page and request it via b is a pretty flawed method.  While it may show 
>that a single aliased call to gettext() doesn't change the execution time 
>of a script by much, it does not say anything about the relative times for 
>execution of a specific function.  You should call the function in  a type 
>loop and average over many executions.  Here's a sample you can try:
>
>strlen.php:
><?
>         $a = 'blah';
>         while($i < 100000) {
>                 $b = strlen($a);
>                 $i++;
>         }
>?>
>
>gstrlen.php:
><?
>         $a = 'blah';
>         while($i < 100000) {
>                 $b = gstrlen($a);
>                 $i++;
>         }
>         function gstrlen($str) {
>                 return strlen($str);
>         }
>?>
>
>
>22:54:00(george@wasabi)[~/src/php-4.0.6/ext]> time php 
>/opt/apache/htdocs/strlen.php
>X-Powered-By: PHP/4.0.6
>Content-type: text/html
>
>0.840u 0.010s 0:00.85 100.0%    0+0k 0+0io 293pf+0w
>
>22:54:17(george@wasabi)[~/src/php-4.0.6/ext]> time php 
>/opt/apache/htdocs/gstrlen.php
>X-Powered-By: PHP/4.0.6
>Content-type: text/html
>
>1.950u 0.010s 0:01.95 100.5%    0+0k 0+0io 295pf+0w
>
>When done often enough, the difference between calling userland functions 
>and builtins is _huge_.  Substitute your favorite function in for strlen 
>(I tried a bunch), you'll get similair results.  Having to switch executor 
>contexts evertime you call a userland function is really expensive.
>
>George
>
>
>
>
>On Saturday, September 8, 2001, at 08:07 PM, Cristopher Daniluk wrote:
>
>>I feel like you're getting a bit personal here, but I'll refrain from doing
>>the same and simply provide numbers. This is a demonstration to prove purely
>>the overhead of going into a userspace function that calls an internal
>>versus calling the internal directly. Obviously this isn't scientific, but
>>that's not my goal.
>>
>>3 scripts were created. First called _(""). Second defined a function as
>>follows:
>>
>>function b($str) { return gettext($str); }
>>
>>Third b("") instead of _("") - note the second one was created just to try
>>and normalize out any deviance from parsing the new function.
>>
>>Apache Bench was run at 1000 queries to give enough performance to
>>illustrate a significant deviance. A concurrency of 10 and 100 were used.
>>Each set was run 3 times and averages were taken to normalize outside
>>factors. Tests were run randomly at various times throughout the last hour,
>>to reduce the effect of foreign elements.
>>
>>First Test (using _)
>>Concurrency 10: 50.24/50.23/57.43 = 52.63
>>Concurrency 100: 44.58/46.59/44.53 = 46.23
>>
>>Second Test (defining b)
>>Concurrency 10: 55.05/56.19/50.55 = 53.93
>>Concurrency 100: 45.65/47.06/45.71 = 46.12
>>
>>Third Test (using b)
>>Concurrency 10: 55.16/55.82/52.16 = 54.38
>>Concurrency 100: 46.74/46.39/47.19 = 46.77
>>
>>I really truly and with all my heart believe that if simply calling a user
>>created function could drop performance by 25%, PHP would not be a viable
>>language. Whether my results are accurate findings or not, Rasmus's
>>demonstration of a 26.3% performance decrease by CALLING A FUNCTION is a lot
>>to swallow!
>>
>>Oh, and I'll refrain from making the muse that the latter test was faster.
>>
>>Having the user make their own function may not be the right solution for
>>this problem, but its phenomenally silly to argue that it would have a large
>>performance impact!
>>
>>Regards,
>>
>>
>>Cristopher Daniluk
>>President & CEO
>>email: [EMAIL PROTECTED]
>>direct: 330/530-2373
>>
>>Digital Services Network, Inc
>>Unleashing Your Potential
>>voice: 800/845-4822
>>web: http://www.dsnet.net/
>>
>>
>>-----Original Message-----
>>From: Chuck Hagenbuch [mailto:[EMAIL PROTECTED]]
>>Sent: Saturday, September 08, 2001 7:23 PM
>>To: [EMAIL PROTECTED]
>>Cc: 'PHP Developer List'
>>Subject: RE: [PHP-DEV] Woah
>>
>>
>>Quoting Cristopher Daniluk <[EMAIL PROTECTED]>:
>>
>>>Agreed, but is the speed loss really worth crying about?
>>
>>Obviously not to you, but I'm pretty sure you came down in the category of
>>people who'd never used gettext.
>>
>>>It is negligible calling a userspace function versus an internal compared
>>to
>>>the greater work that the typical PHP script does.
>>
>>What authority do you have to make this statement? Rasmus posted numbers.
>>Where
>>are yours?
>>
>>-chuck
>>
>>--
>>Charles Hagenbuch, <[EMAIL PROTECTED]>
>>Some fallen angels have their good reasons.
>>
>>--
>>PHP Development Mailing List <http://www.php.net/>
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>>To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>
>
>>--
>>PHP Development Mailing List <http://www.php.net/>
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>>To contact the list administrators, e-mail: [EMAIL PROTECTED]
>


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to