?
Solved

How to measure execution time?

Posted on 2001-09-03
3
Medium Priority
?
1,978 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 400 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

All of the resources available today make learning a new digital media easier than ever-- if you know where to begin. This is a clear, simple guide to a few of the basic digital art mediums and how to begin learning them on your own.
In this article I discuss my selections of the Top Four free Outlook OST File Viewers available. Open, view and read even damaged OST files by using these tools. They all provide a clear preview of all data such as emails, notes, tasks, calendars, e…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

801 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