Re: Re: PHP Performance and System Load
| From: | Sancar Saran | Date: | Fri, 20 Jul 2007 23:18:07 +0000 |
| Subject: | Re: Re: PHP Performance and System Load | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-259255@lists.php.net to get a copy of this message | ||
Hi,
I had lots of loop in my code. My gain was %4 to %6 and I say "may gain
another %10". Of course your millage was different than me
Regards
Sancar
On Saturday 21 July 2007 01:03:45 Richard Lynch wrote:
> On Fri, July 20, 2007 4:16 am, Colin Guthrie wrote:
> > Sancar Saran wrote:
> >> Another simple performance tip.
> >>
> >> Most of for examples of php look like this
> >> for($x=0;$x<sizeof($arrSometing);$x++)
> >>
> >> This is bad. In every cycle you call sizeof
> >>
> >> this was good
> >> $intSize = sizeof($arrSometing);
> >> for($x=0;$x<$intSize;$x++)
> >>
> >> if u use.
> >> for($x=0;$x<$intSiz;++$x). You may gain another %10
> >>
> >> to determine costs of your functions use xdebug and kcachegrind.
> >
> > I've always used pre-increment in loops like you suggest as it was an
> > ingrained part of my C/C++ learning from a performance perspective. I
> > wasn't sure if the same was true in PHP but you seem to suggest it is,
> > so I feel justified now :)
>
> I don't really care if one uses pre or post, but I just benchmarked
> this, and I don't really think it makes a 10% win.
>
> And I had to crank it up to 10 MILLION to get any kind of realistic
> measurable time in the first place.
>
> How often do you have a PHP loop that runs to 10 MILLION iterations?!
>
> Note that I did three with pre before post tests and three post before
> pre tests to even out any caching effects.
>
> Test environment details at the bottom.
>
> sagacitydev@ch10106cus002 ~/junk $ cat pre.php post.php
> <?php
> for ($i = 0; $i < 10000000; ++$i);
> ?>
> <?php
> for ($i = 0; $i < 10000000; $i++);
> ?>
> sagacitydev@ch10106cus002 ~/junk $ time php -q pre.php ; time php -q
> post.php
>
> real 0m5.422s
> user 0m5.350s
> sys 0m0.070s
>
> real 0m5.397s
> user 0m5.330s
> sys 0m0.070s
> sagacitydev@ch10106cus002 ~/junk $ time php -q pre.php ; time php -q
> post.php
>
> real 0m5.164s
> user 0m5.090s
> sys 0m0.070s
>
> real 0m5.310s
> user 0m5.230s
> sys 0m0.080s
> sagacitydev@ch10106cus002 ~/junk $ time php -q pre.php ; time php -q
> post.php
>
> real 0m5.093s
> user 0m5.030s
> sys 0m0.070s
>
> real 0m5.387s
> user 0m5.300s
> sys 0m0.080s
> sagacitydev@ch10106cus002 ~/junk $ time php -q post.php ; time php -q
> pre.php
>
> real 0m5.429s
> user 0m5.340s
> sys 0m0.070s
>
> real 0m5.140s
> user 0m5.060s
> sys 0m0.080s
> sagacitydev@ch10106cus002 ~/junk $ time php -q post.php ; time php -q
> pre.php
>
> real 0m5.348s
> user 0m5.270s
> sys 0m0.070s
>
> real 0m5.101s
> user 0m5.030s
> sys 0m0.070s
> sagacitydev@ch10106cus002 ~/junk $ time php -q post.php ; time php -q
> pre.php
>
> real 0m5.376s
> user 0m5.300s
> sys 0m0.080s
>
> real 0m5.009s
> user 0m4.910s
> sys 0m0.100s
>
> sagacitydev@ch10106cus002 ~/junk $ php -v
> PHP 4.4.7 (cli) (built: May 8 2007 09:49:19)
> Copyright (c) 1997-2007 The PHP Group
> Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
>
> sagacitydev@ch10106cus002 ~/junk $ uname -a
> Linux ch10106cus002 2.6.18-hardened-r6 #2 SMP Tue Apr 17 09:15:05 CDT
> 2007 i686 Dual Core AMD Opteron(tm) Processor 270 AuthenticAMD
> GNU/Linux
> sagacitydev@ch10106cus002 ~/junk $
>
> Perhaps the OP meant that not doing the count() / sizeof() on every
> iteration was a 10% win? Now *THAT* I can believe!
>
> --
> Some people have a "gift" link here.
> Know what I want?
> I want you to buy a CD from some indie artist.
> http://cdbaby.com/browse/from/lynch
> Yeah, I get a buck. So?