|
Posted by sumeet on 10/13/33 11:26
Senator Jay Billington Bulworth wrote:
> sumeet <sumeet72@gmail.com> wrote in news:dg0kvi$m4a$1
> @domitilla.aioe.org:
>
>
>>
> Hi,
>
> Testing things on a single iteration is not reliable. A script might run
> in a tenth of a second one time, and take three seconds to run the next
> time, depending upon system load, amount of free RAM, etc. Benchmarking
> should involve running a command sequence for some large number of times,
> and timing the response.
>
> I'm not familiar with the Benchmark class you seem to be using, so I ran
> a local test using both examples.
>
> Script 1:
>
> <?php
> $str = 'Sumeet Shroff';
> for($i=0; $i<100000; $i++){
> echo $str;
> }
> ?>
>
> [shaun@winfosec temp]$ time php echotime1.php >outfile
>
> real 0m0.508s
> user 0m0.016s
> sys 0m0.492s
>
> Script 2:
>
> <?php
> $str = 'Sumeet Shroff';
> for($i=0; $i<100000; $i++){
> for($j=0; $j<strlen($str); $j++){
> echo $str[$j];
> }
> }
> ?>
>
> [shaun@winfosec temp]$ time php echotime2.php >outfile
>
> real 0m13.222s
> user 0m1.273s
> sys 0m11.941s
>
> As you can see, the first script printed out "Sumeet Shroff" 100,000
> times in approximately half a second. The second script, which iterated
> through each character in the string "Sumeet Shroff," took 13 seconds to
> print out your name 100,000 times.
>
> Don't rely on a single iteration to optimize your loops. Try running them
> several hundreds of thousands of times, and see which one comes out on
> top.
>
> hth
>
thanks Jay,
you have been very helpful.
sumeet shroff
[Back to original message]
|