Let's just make the supposition for a second that you're right, that the
difference between calling a userspace function over an internal function is
going to create phenomenal decreases in overall execution time. The
implication I believe you give is that over an amortized amount of time,
execution speed between calling a userland function and internal function
will be approximately 2x. This is just mind boggling! Sure, there's roughly
twice the work to call a user function wrapper compared to calling the
internal. There's also the loss in parsing. However, do not make the fatal
mistake of assuming that twice the cost of an operation translates to twice
the cost of a process, or for that matter, even a negligible cost increase.
PHP would not, and I can't make this clear enough, would NOT be a viable
option in the market if the performance loss in real world scenarios from
simply entering into a function was that great. I'd venture (these are
SWAGs) to say that a single call to preg_replace does over 500x more machine
instructions than calling a userland function. I bet the gettext call
itself, which is the focal point of this discussion, does 50x more machine
instructions, than the function call that's wrapping it. If you look at it
on a microcosmic sense, there is a clear and real difference, but when you
analyze on a macro level, you clearly can't argue there is a performance
loss worth caring about. It's just childish and foolish and arguing it makes
you look truly foolish. If you don't believe that, imagine for a tenth of a
second that you're right, and think about the implications.

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: George Schlossnagle [mailto:[EMAIL PROTECTED]]
Sent: Sunday, September 09, 2001 9:57 AM
To: Zeev Suraski
Cc: [EMAIL PROTECTED]; 'Chuck Hagenbuch'; 'PHP Developer List'
Subject: Re: [PHP-DEV] Woah


Replaced with a call to strstr and function declaration placed ahead of
usage  (althoough I disagree about how much faster this will make it.  I
only declare the function once and loop it, so whether
do_bind_function_or_class is called on it during compile or once during
execution should be a minimal difference):

9:43:36(george@wasabi)[~/src/php-4.0.6/ext]> time php
/opt/apache/htdocs/strstr.php
X-Powered-By: PHP/4.0.6
Content-type: text/html

1.140u 0.040s 0:02.02 58.4%     0+0k 0+0io 568pf+0w

9:43:40(george@wasabi)[~/src/php-4.0.6/ext]> time php
/opt/apache/htdocs/b.php
X-Powered-By: PHP/4.0.6
Content-type: text/html

2.350u 0.000s 0:02.35 100.0%    0+0k 0+0io 296pf+0w


and with preg_match:
9:50:05(george@wasabi)[~/src/php-4.0.6/ext]> time php
/opt/apache/htdocs/preg_match.php
X-Powered-By: PHP/4.0.6
Content-type: text/html

1.520u 0.000s 0:01.51 100.6%    0+0k 0+0io 303pf+0w

9:50:10(george@wasabi)[~/src/php-4.0.6/ext]> time php
/opt/apache/htdocs/gpreg_match.php
X-Powered-By: PHP/4.0.6
Content-type: text/html

2.880u 0.010s 0:02.88 100.3%    0+0k 0+0io 304pf+0w


I realize these are still relatively simple functions, but the point of
this excercise is demonstrate the inherent speed differences between
internal and userland functions, whihc I think it does.  Also 'simple'
functions are (totally my supposition, based on my experience) usually
the functions people use heavily inside there own code.

On Sunday, September 9, 2001, at 03:25 AM, Zeev Suraski wrote:

> 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: php-list-
>>> [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: php-list-
>>> [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: php-list-
>>> [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: php-list-
>>> [EMAIL PROTECTED]
>>
>
BEGIN:VCARD
VERSION:2.1
N:Daniluk;Cristopher
FN:Cristopher Daniluk
ORG:Digital Services Network, Inc.;Executive Management
TITLE:President & CEO
NOTE;ENCODING=QUOTED-PRINTABLE:=0D=0A
TEL;WORK;VOICE:(330) 530-2373
TEL;WORK;VOICE:(800) 845-4822
TEL;CELL;VOICE:(330) 219-4819
TEL;WORK;FAX:(208) 723-6782
ADR;WORK;ENCODING=QUOTED-PRINTABLE:;President;89 West Marshall Avenue=0D=0ASuite A;McDonald;Ohio;44437;United S=
tates of America
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:President=0D=0A89 West Marshall Avenue=0D=0ASuite A=0D=0AMcDonald, Ohio 4443=
7=0D=0AUnited States of America
URL;WORK:http://www.dsnet.net/~cris
EMAIL;PREF;INTERNET:[EMAIL PROTECTED]
REV:20010528T230445Z
END:VCARD

-- 
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