Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6816007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:52:29+00:00 2026-05-26T20:52:29+00:00

I am trying to calculate the time it takes a query to run using

  • 0

I am trying to calculate the time it takes a query to run using a php script:

For example:

$sql = "SELECT COUNT(*) FROM `order_items` LEFT JOIN `orders` ON `oi_o_id` = `o_id` WHERE `o_status` = 'completed' AND `oi_p_id` = '10' LIMIT 1";
$sqlStart = getMicroTime();
$result = mysql_query($sql);
$sqlEnd = getMicroTime();
$sqlTime = $sqlEnd - $sqlStart;

echo $sqlTime;

function getMicroTime() {
    list($msec, $sec) = explode(' ', microtime());
    return floor($sec / 1000) + $msec;
}

This appears to work most of the time, but occasionally I get a negative value e.g. -0.98840499995276. How is this possible? and is there a better way to get the query execution time?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:52:29+00:00Added an answer on May 26, 2026 at 8:52 pm

    Your microtime function is not necessary, simply do

    $start = microtime(TRUE);
    ... do query
    $end = microtime(TRUE);
    

    passing in the TRUE value has microtime() return the timestamp as an actual float, not that moronic string format that some [truly nasty but accurate description of said person’s intelligence] thought would be a useful way of returning the data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to calculate time blocks from given date range. Here's my attempt: <?php
Trying to get a simple COUNT from a table that takes a couple of
How do I calculate development time (hours) using COCOMO2? I am trying to calculate
In fact i am trying to calculate the time a function takes to complete
am trying to calculate mean and variance using 3X3 window over image(hXw) in opencv...here
I am trying to calculate a determinant using the boost c++ libraries. I found
I'm trying to calculate the sunset / rise times using python based on the
I am trying to find out the average time it takes various pages of
I'm trying to optimize a report query run on an ecommerce site. I'm pretty
I am trying to calculate the time difference between 2 time and put the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.