Solved

How to measure execution time?

Posted on 2001-09-03
3
1,961 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
Comment Utility
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
Comment Utility
Thanks! My script takes 0.1 s on average -- quite fast.
0
 
LVL 1

Expert Comment

by:pantherchen
Comment Utility
with db-accesses? that really fast :)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
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.
The viewer will learn how to count occurrences of each item in an array.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now