Forum Topic: Speed test of code

(151 views • 3 replies)

This topic is 1 page long.

<< < > >>
None

Loccie

Reply To Post Reply & Quote

Posted at: 5/2/09 09:29 PM

Loccie NEUTRAL LEVEL 16

Sign-Up: 02/27/04

Posts: 1,059

How can I test how fast certain code is executed in PHP? For example the time it takes to run a certain loop.


None

WoogieNoogie

Reply To Post Reply & Quote

Posted at: 5/2/09 10:00 PM

WoogieNoogie LIGHT LEVEL 14

Sign-Up: 06/26/05

Posts: 3,284

I'm pretty sure there's some timer function, but I can't find it. So, quick fix...

$var1 = microtime();
while (condition) {
loop;
}
$var2 = microtime();
$timeItTook = $var2 - $var1;

Yay pseudocode.


None

Loccie

Reply To Post Reply & Quote

Posted at: 5/3/09 05:09 AM

Loccie NEUTRAL LEVEL 16

Sign-Up: 02/27/04

Posts: 1,059

Yes, that seems to work. Thanks.


None

Deja-Vu

Reply To Post Reply & Quote

Posted at: 5/4/09 03:45 PM

Deja-Vu NEUTRAL LEVEL 25

Sign-Up: 05/03/02

Posts: 554

You could also use the PEAR Benchmark package - http://pear.php.net/package/Benchmark (a little more involved).

BBS Signature

All times are Eastern Standard Time (GMT -5) | Current Time: 11:01 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!