I already have a timer on how long it takes the page to load and would like one so that I can keep an eye on my queries. Well, that's the official reason. The real reason is I'm just curious
returning time from MySQL select
Moderator: General Moderators
returning time from MySQL select
How do I get the time that it takes for a MySQL SELECT statement to run? I need to be able to display it like: "Select query executed in x.xx seconds"
I already have a timer on how long it takes the page to load and would like one so that I can keep an eye on my queries. Well, that's the official reason. The real reason is I'm just curious
I already have a timer on how long it takes the page to load and would like one so that I can keep an eye on my queries. Well, that's the official reason. The real reason is I'm just curious
Hmm..the only way I can think to do it off the top of my head is to use microtime()...something like :
function GetMicrotime() {
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
$starttime = GetMicrotime();
//do your query here
$endtime = GetMicrotime();
$totaltime = $endtime - $starttime;
echo 'Query executed in $totaltime seconds.";
Not perfect and the calculations and function calls do add a little bit in there. But, it will give you an estimate...
function GetMicrotime() {
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
$starttime = GetMicrotime();
//do your query here
$endtime = GetMicrotime();
$totaltime = $endtime - $starttime;
echo 'Query executed in $totaltime seconds.";
Not perfect and the calculations and function calls do add a little bit in there. But, it will give you an estimate...