Php Execution Time Function – Multiple Times

I just hate how many “complicated” classes there are for testing your script performance. so i wrote a simple function to do that.

function runtimer($cmd){
     global $timearray;
     global $starttime;

     if($cmd == "start"){
	    $starttime = microtime();
     }

     if($cmd == "end"){
		$endtime = microtime();
	    $timearray[] = $endtime - $starttime;
     }
     if($cmd == "get"){
	 return $timearray;
     }
     return false;
}

runtimer("start");
runtimer("end");
runtimer("start");
runtimer("end");

print_r(runtimer("get"));


This entry was posted in everyday tips. Bookmark the permalink.