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

  • Home
  • SEARCH
  • 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 289897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:56:55+00:00 2026-05-12T05:56:55+00:00

I need a simple way to test SQL queries for speed. I am not

  • 0

I need a simple way to test SQL queries for speed. I am not to worried about hardware differences, I basically need a relative number.

This is what I’ve been doing with PHP (its fuzzy, but works):

// CONNECT TO DB HERE

$sub = new YomoSubscription(95,783);

$t = microtime(TRUE);

// contains the SQL db call i'm testing
$fp = $sub->generateFingerprint(); 

echo microtime(TRUE)-$t;

The PROBLEM I am having is that, sometimes on initial connect/run my test takes 1.25 sec for example. However on subsequent connects it takes 0.004 sec … Why is this?

I’m pretty sure MySQL query cache is off in my.ini:

query_cache_size=0
  • 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-12T05:56:55+00:00Added an answer on May 12, 2026 at 5:56 am

    Your first query may be slower because MySQL is actually hitting the disk on the first query, and not on the second.

    Your operating system may cache files in memory as they are read; as a result, subsequent reads may not need to actually hit the disk, and will return much faster.

    As a rule of thumb, I generally run a query a few times, and look for consistency. More often than not, the first run will take several times longer, while the 2nd 3rd and 4th take about the same amount of time. Those subsequent runs are probably more representative of the sort of performance you’ll see on an actual production system — since your production database should keep that data in the OS cache, while your dev system is rarely accessed.

    In the end, when it comes to query performance, for the most part, you should just give it a quick pass in development, and monitor the slow query log in production to see which queries really need work.

    As far as programatically running queries for performance data goes — take several samples, and use the median. But in practice, this isn’t going to be terribly representative of the actual performance issues you’ll run into in production.

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

Sidebar

Ask A Question

Stats

  • Questions 136k
  • Answers 136k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In bikehireform.php change the line that says startGallery(); to window.addEvent('domready',… May 12, 2026 at 7:05 am
  • Editorial Team
    Editorial Team added an answer Couldn't you just use two loops? For i = 0… May 12, 2026 at 7:05 am
  • Editorial Team
    Editorial Team added an answer % is modulo, so $num_one = rand() % 10 gives… May 12, 2026 at 7:05 am

Related Questions

I have a number of different data sources that I need to query and
I have a project here that connects to an in-production database and grabs tables
Anyone know of a good way to unit test Scala actors? In the general
I have a very large CSV file and I need to write an app
I'm trying to set up an XSL:IF statement that only shows entries that have

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.