Solved

How to measure execution time?

Posted on 2001-09-03
3
1,967 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
  • 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

If your app took Google’s lash recently, here are the 5 most likely reasons.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
Video by: Tony
This video teaches viewers how to export a project from Adobe Premiere Pro and the various file types involved.
The viewer will learn how to dynamically set the form action using jQuery.

773 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