visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Databases :: MySql :: cpu time mysql


By: Nono Great Britain  Date: 14/06/2007 14:11:59  English  Points: 20 Status: Answered
Quality : Excellent
how to get the cpu time for a mysql query ?
By: VGR Date: 14/06/2007 14:56:55 English  Type : Answer
well, except in the "mysql console", mysqld does not return execution time.

You probably won't have the real "CPU time" unless you can read twice the "task manager"/"ps" output before and after the query run, but you can get the "overall execution time" by just measuring the difference between system time before and after the query run.

That's relatively easy.

Here is sample code : (I use a session variable, but you can adapt)

<?php // //VGR14042001 Creation //VGR24112002 ADDed sécurité pour mode globDisc // // // ----------------------------- FORUM ----------------------------------- // function myTime() { // en secondes $loc1=microtime(); $loc2 = (double)substr (strrchr ($loc1, ' '), 1); // secondes entières $loc3 = (double)substr ($loc1, 1,strpos($loc1,' ')); // fraction de seconde = 0.xxx $loc2 = (double)$loc2+$loc3; return $loc2; } function TimerStart() { GLOBAL $_SESSION; $_SESSION['TTime']=myTime(); } // TimerStart Procedure function TimerStop($parDisp=FALSE) { // and display GLOBAL $_SESSION; $locTime=myTime()-$_SESSION['TTime']; // en secondes //VGR14042001 BUGFIX // il y a un bug dans la fonction de base : la seconde n'est pas incrémentée correctement. if ($locTime<0) $locTime=1.0+$locTime; //EoFIX $locTime=round(1000.0*$locTime,5); // millisecondes arrondies à la 5ème décimale if ($parDisp) echo " <CENTER><font size=-2>page generated in $locTime milliseconds</font></CENTER>"; return($locTime); } // TimerStop Integer (ms) Function ?>



usage :

TimerStart(); mysql_query(etc etc etc); $timeused=TimerStop(TRUE); // will display a message // or $timeused=TimerStop(FALSE); echo "the query executed in $timeused milliseconds";


Do register to be able to answer

EContact
browser fav
page generated in 293.305870 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page