Benchmarking in PHP
/*--- holy mAcar00ns!! --- */
As I expressed in the introduction, one of the simplest ways to create a basic benchmarking mechanism relies on using the “microtime()” built-in PHP function. Just in case you didn’t know, this function returns the current Unix timestamp, which additionally appends the corresponding microseconds to the output.
// define 'getMicrotime()'function in PHP 4
function getMicrotime(){
list($useg,$seg)=explode(' ',microtime());
return ((float)$useg+(float)$seg);
}
The “getMicrotime()” function that I defined above demonstrates a classic use of “microtime()” to construct a basic benchmarking system. It’s one of the most common implementations of the function that I ever saw.
That being said, let me go one step further and show you a simple example of how to use the previous “getMicrotime()” function inside of a benchmarking script. Here is the pertinent code sample:
$startTime=getMicrotime();
// do nothing for a while
usleep(100);
$endTime=getMicrotime();
$totalTime=$endTime-$startTime;
echo 'Time spent in doing nothing was '.$totalTime.' seconds';
Read.
Labels: php
all your bases ar--
ping moi pleeez
About this entry
You’re reading “
- Published:
- 4:36 PM
pacman is coming
nuck nuck
e belong to us!
0 Comments (Post a Comment)