A
A
Arseniy2014-05-16 05:15:46
MySQL
Arseniy, 2014-05-16 05:15:46

How to calculate the execution time of SQL queries?

It is necessary to calculate the execution time of sql queries, but sometimes my timing function returns 0, despite the fact that the query is quite normal and returns some result...

public double GetQueryTime(string query)
{
            TimeSpan duration;
            DateTime start = DateTime.Now;
            cmd = new MySqlCommand(query, con);
            using (MySqlDataReader rdr = cmd.ExecuteReader())
            {
                while (rdr.Read()) { };
            }
            duration = DateTime.Now.Subtract(start);
            return duration.TotalMilliseconds;
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2014-05-16
@Rsa97

Try it via DateTime.Ticks

Y
Yurii Medvedev, 2014-05-27
@kin9pin

Use stopwatch

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question