Page 1 of 1

Query time

Posted: Thu Mar 15, 2007 12:19 pm
by GeXus
How do you find out how long it takes for a query to run?

Posted: Thu Mar 15, 2007 12:42 pm
by mikeq
stopwatch :twisted:

Re: Query time

Posted: Wed Mar 21, 2007 12:12 am
by califdon
GeXus wrote:How do you find out how long it takes for a query to run?
If you're using MySQL from the command line, it displays the time in seconds at the end of the results. What are you trying to do, optimize a query? If you are, I'd suggest that you check into the available tools for optimizing. There are lots of little 'gotchas' that won't necessarily be obvious just from the raw time it takes to run. For example, are there other concurrent users of the database? I'd have to research it myself, but I'm pretty sure there are built-in environment variables that hold the query time of the most recent query.

Now, in case you're not using MySQL, or even if you are, an option would be to write a test PHP script that saves the timestamp just prior to running the query, then immediately getting another timestamp and subtracting the two.

Posted: Wed Mar 21, 2007 11:05 am
by RobertGonzalez
If you want to do this with PHP, have a look at the example code on the microtime() manual page.

Posted: Fri Mar 23, 2007 8:00 pm
by GeXus
Thanks everyone, I installed mysql administrator which has query browser and that shows the execution time.. it seems to do the job for now..

Posted: Sat Mar 24, 2007 10:17 am
by RobertGonzalez
phpMyAdmin does as well, though the DB tools usually show it a tad more accurately.