how to count execution time of sql query ?

Discussion in 'PHP' started by ramysarwat, Nov 12, 2009.

  1. #1
    how to count execution time of sql query ?
     
    ramysarwat, Nov 12, 2009 IP
  2. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #2
    I'm not sure if there is direct function for this, but to keep it simple, i would do microtime() before and after query and do subtraction :)
     
    mastermunj, Nov 12, 2009 IP
  3. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #3
    Simple way to do it is

    $starttime = microtime();
    $query = mysql_query("select * from table");
    $endtime = microtime();
     
    Bohra, Nov 12, 2009 IP
  4. iama_gamer

    iama_gamer Active Member

    Messages:
    404
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Remember though this time wont be a constant for a query and will depend on caching. For worst case time, flush and perform this
     
    iama_gamer, Dec 14, 2010 IP