tags:

views:

48

answers:

1

Hey

How do i test the speed of a database call from PHP?

I interested in testing how many miliseconds it takes my script to call the database with a query and gets the result. For example how many milisecond would the query below take to execute:

SELECT * FROM customers OrderBy customer_id

Thanks in advance.

+4  A: 

Quick and dirty:

$q = "SELECT foo FROM BAR";
$start = microtime(true);
$res = query($q);
$end = microtime(true);

echo "Query took " . ( $end-$start) . " seconds";
timdev
Actually, microtime() returns microseconds, not seconds.
Davide Gualano
Passing true as the first argument makes microtime return the time as a float. Expected output would be "Query took X.Y seconds"
timdev
I didn't know that, thanks :)
Davide Gualano