Benchmarking in PHP

/*--- holy mAcar00ns!! --- */

Article on basic benchmarking in PHP:

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:

// do nothing for a while
echo 'Time spent in doing nothing was '.$totalTime.' seconds';



all your bases ar--

ping moi pleeez

About this entry

pacman is coming

nuck nuck

e belong to us!