Solved

How to measure execution time?

Posted on 2001-09-03
3
1,971 Views
Last Modified: 2013-11-15
In my MySQL based page I perform series of database queries in very simple manner, not thinking about optimizing. I'd like to measure execution time of this piece of code on server side to detect whether non-optimized code is slowing my page or not.

How do I do it in PHP?
0
Comment
Question by:Robson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
pantherchen earned 100 total points
ID: 6450456
Many service-provider offer "benchmarks" for PHP-scripts.

You can do it by yourselft in the following way:

3 pieces of code:


1: take the start time:

$start = microtime();


2: take the end time:

$end = microtime();


3: calculate the difference and echo it:

$start = explode(" ",$start);
$end = explode(" ",$end);
$diff = ($end[0] + $end[1]) - ($start[0] + $start[1]);

echo $diff;



Put the first part before the code you wanna test.
Put the second part after the code you wanna test.
Put the third part after the second part (so the calculation istn counted).

The Value you get is the "execution time" between the $start and the $end in seconds (so for short scripts its normal to get something like "0.00004324234").


Hope that helps, Panther :)
0
 
LVL 4

Author Comment

by:Robson
ID: 6450547
Thanks! My script takes 0.1 s on average -- quite fast.
0
 
LVL 1

Expert Comment

by:pantherchen
ID: 6450582
with db-accesses? that really fast :)
0

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
This video demonstrates how to use each tool, their shortcuts, where and when to use them, and how to use the keyboard to improve workflow.
This video will demonstrate how to find the puppet warp tool from the edit menu and where to put the points to edit.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question