views:

658

answers:

7

How can I say which class of many (which all do the same job) execute faster? is there a software to measure that?

+1  A: 

If it's something that can be tested outside the Web context, I just use the Unix time command.

chaos
What about windows?
MAK
+3  A: 

For quick stuff I do this (in PHP):

$startTime = microtime(true);
doTask(); // whatever you want to time
echo "Time:  " . number_format(( microtime(true) - $startTime), 4) . " Seconds\n";

You can also use a profiler like http://xdebug.org/.

Scott Saunders
For additional accuracy, I'd suggest (a) using a loop and averaging the time and (b) using separate files for each thing you're testing. If you have several timings within one script, their order can make a difference sometimes.
DisgruntledGoat
A: 

You can use basic stuff like storing timestamps or microtime() before and after an operation to calculate the time needed. That's easy to do, but not very accurate. Maybe a better solution is Xdebug, i've never worked with it but it seems to be the best-known PHP debugger/profiler I can find.

Alex Kamsteeg
+2  A: 

webgrind + xdebug

troelskn
Any more details? :)
MAK
Honestly I'm not sure what to add. [Download + install xdebug](http://www.xdebug.org/docs/install) (it's a php-extension). Then [configure it to profile your script](http://www.xdebug.org/docs/profiler#starting). This will generate a cachegrind file. You can then use webgrind to view the cachegrind file with. (Or another viewer. If you use Windows, you could use [wincachegrind](http://sourceforge.net/projects/wincachegrind/))
troelskn
+1  A: 

Zend Studio has built in support for profiling using XDebug or ZendDebugger. It will profile your code, telling you exactly how long every function took. It's a fantastic tool for figuring out where your bottlenecks are.

OverloadUT
+5  A: 
Pascal MARTIN
+1  A: 

ive been using xhprof lately http://pecl.php.net/package/xhprof. It was originally developed by facebook and it comes with a decent we interface.

Jason