Re: Woah
| From: | George Schlossnagle | Date: | Sun, 09 Sep 2001 13:57:10 +0000 |
| Subject: | Re: Woah | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-65578@lists.php.net to get a copy of this message | ||
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+0w9: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+0wand 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+0w9: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+0wI 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/html0.840u 0.010s 0:00.85 100.0% 0+0k 0+0io 293pf+0w22: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/html1.950u 0.010s 0:01.95 100.5% 0+0k 0+0io 295pf+0wWhen 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: cris@dsnet.net 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:chuck@horde.org] Sent: Saturday, September 08, 2001 7:23 PM To: cris@dsnet.net Cc: 'PHP Developer List' Subject: RE: [PHP-DEV] Woah Quoting Cristopher Daniluk <cris@dsnet.net>:<Attachment missing>> --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 comparedtothe 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, <chuck@horde.org> Some fallen angels have their good reasons. -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net For additional commands, e-mail: php-dev-help@lists.php.net To contact the list administrators, e-mail: php-list- admin@lists.php.netPHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net For additional commands, e-mail: php-dev-help@lists.php.net To contact the list administrators, e-mail: php-list- admin@lists.php.netBenchmarking 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/html0.840u 0.010s 0:00.85 100.0% 0+0k 0+0io 293pf+0w22: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/html1.950u 0.010s 0:01.95 100.5% 0+0k 0+0io 295pf+0wWhen 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: cris@dsnet.net 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:chuck@horde.org] Sent: Saturday, September 08, 2001 7:23 PM To: cris@dsnet.net Cc: 'PHP Developer List' Subject: RE: [PHP-DEV] Woah Quoting Cristopher Daniluk <cris@dsnet.net>: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 comparedtothe 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, <chuck@horde.org> Some fallen angels have their good reasons. -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net For additional commands, e-mail: php-dev-help@lists.php.net To contact the list administrators, e-mail: php-list- admin@lists.php.net-- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net For additional commands, e-mail: php-dev-help@lists.php.net To contact the list administrators, e-mail: php-list- admin@lists.php.net