poirot Posted June 6, 2006 Share Posted June 6, 2006 Hello,I am using a very basic code to calculate execution time:[code]<?php$start = microtime();// Some code here$exec = microtime() - $start;echo 'Page Generated in ' . $exec . ' microseconds';?>[/code]Is this OK? Oddly enoug, sometimes I get weird negative results [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /] ...And what would be a good value for that? I have pages in my site that are executed in 0.01 ms, but some others take 0.08 microseconds.And they do almost the same thing - in fact, it's the same script, but calling different functions. Yet, 8 times slower.Note: I'm running a local test server; my machine is an athlon 64 3800+, 2gb of ram. Way below the specs of real server then.Thanks in advance [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] Quote Link to comment https://forums.phpfreaks.com/topic/11300-page-execution-time/ Share on other sites More sharing options...
.josh Posted June 6, 2006 Share Posted June 6, 2006 lol..negative results? maybe your computer is so fast it moves backwards in time. Or maybe it's so intuitive that future version of your computer sends the results back in time to present time. [img src=\"style_emoticons/[#EMO_DIR#]/laugh.gif\" style=\"vertical-align:middle\" emoid=\":laugh:\" border=\"0\" alt=\"laugh.gif\" /]man i dunno why it would do that, to be honest. but i suppose you can throw and if statement in there to catch it. like[code]echo "time to generate: ";if ($exec < 0) { echo "instant!"; //..or just 0 or somethin'} else { echo $exec;}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11300-page-execution-time/#findComment-42310 Share on other sites More sharing options...
poirot Posted June 7, 2006 Author Share Posted June 7, 2006 I found a quick fix for the negative results.It may be avoided if I use microtime(true) instead of microtime()(sets get_as_float) - will return a float.Unfortunately, this parameter was added as of PHP5. What should I do for older versions? Quote Link to comment https://forums.phpfreaks.com/topic/11300-page-execution-time/#findComment-42934 Share on other sites More sharing options...
Buyocat Posted June 7, 2006 Share Posted June 7, 2006 Poirot this may be overkill, but there is a pear package built specifically for benchmarking that you could use.[a href=\"http://pear.php.net/package/Benchmark\" target=\"_blank\"]http://pear.php.net/package/Benchmark[/a]I've used it once or twice in the past and it's pretty straightforward. Installation is obviously easy. Quote Link to comment https://forums.phpfreaks.com/topic/11300-page-execution-time/#findComment-42951 Share on other sites More sharing options...
poirot Posted June 7, 2006 Author Share Posted June 7, 2006 Thanks Buyocat, but I need something very simple, that I can use whenever I want.I don't know if that's overkill, but I like to code everything I use, so I can write it "of head" [what's the proper term for this?]. Quote Link to comment https://forums.phpfreaks.com/topic/11300-page-execution-time/#findComment-42961 Share on other sites More sharing options...
Buyocat Posted June 7, 2006 Share Posted June 7, 2006 Off hand maybe? Off the top of your head? I have no idea. The nice thing about the package is that it is easy to use whenever you want, and you can use it alongside test scripts etc. But I do understand the desire to do things yourself, though I can't say that's a good quality sometimes. Still this is probably an easy enough problem that your solution is just as good. Quote Link to comment https://forums.phpfreaks.com/topic/11300-page-execution-time/#findComment-42971 Share on other sites More sharing options...
nogray Posted June 8, 2006 Share Posted June 8, 2006 [a href=\"http://us2.php.net/manual/en/function.microtime.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.microtime.php[/a] have an example of getting the exection time in php 4 and 5 Quote Link to comment https://forums.phpfreaks.com/topic/11300-page-execution-time/#findComment-43010 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.