I am currently using this function to benchmark some php scripts, the script gets the microtime it takes to execute, and writes it to a log on the server, but the problem i am having is that i have no idea what are some decent times. the script is below followed by some of my times, can anyone give me an idea on what kind of times i want to be within the range of?
PLACE AT THE BEGINNING OF THE PAGE
global $start_time; $start_time = microtime();
PLACE AT THE END OF THE PAGE
global $start_time;
$ra_start = explode(' ', $start_time);
$ra_end = explode(' ', microtime());
$cpu_time = ($ra_end[1]+$ra_end[0]) - ($ra_start[1]+$ra_start[0]);
$f = fopen('/home/mcbeav/cpu_usage.log', 'a', 1);
// time seconds request by_ip
fwrite($f, date('m-d-Y H:m')."\t".$cpu_time."\t".$_SERVER['SERVER_NAME']."\t".$_SERVER['PHP_SELF']."\t".$_SERVER['REMOTE_ADDR']."\n");
fclose($f);
RESULTS FOR THE SAME PAGE
0.10285401344299
0.021783828735352
0.018580913543701
0.042204856872559
You can use
microtime(TRUE);
and get a whole number back, these days. No need for explode() and addition.Regarding your times, you should be looking at fairly low execution times for a script like this (assuming this is all the script is actually doing). However, execution may take some more time depending on the I/O load on the system. Judging from the given script, and the execution time, I'm guessing the system you're trying to do this on might be doing a fair bit of I/O work and there's not much you can do to improve it from your PHP script.
Though I am not sure I got your question right, everything is starting from 0.0 is okay. So, you have to watch the ascipt running 0,1 more closely
just to refactor your code a bit to make it less ancient-looking.
it depends on what you are doing. is a lot happening?
Here is a benchmarking class I made a long time ago. You make markers where ever in your code (start, end, etc) with a static method, then print out a report at the bottom of your page with another static method. also keeps track of memory usage. this is somewhat messy since it uses static methods. The better thing might be to profile your code using XDebug:
I'm not sure if I get you right, but it seems to me you basically don't know if you have performance problem yet or not, correct? If so - you don't. No need wasting time building pointless benchmarks. Focus on actual code. Come back to profiling when the app starts to feel slow for real.