Jump to content


Photo

Page Execution Time


  • Please log in to reply
6 replies to this topic

#1 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 06 June 2006 - 05:17 AM

Hello,

I am using a very basic code to calculate execution time:

<?php

$start = microtime();

// Some code here

$exec = microtime() - $start;
echo 'Page Generated in ' . $exec . ' microseconds';

?>

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\" /]
~ D Kuang

#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 06 June 2006 - 05:22 AM

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

echo "time to generate: ";
if ($exec < 0) {
  echo "instant!"; //..or just 0 or somethin'
} else {
  echo $exec;
}

Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 07 June 2006 - 08:31 PM

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?
~ D Kuang

#4 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 07 June 2006 - 09:02 PM

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.
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#5 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 07 June 2006 - 09:19 PM

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?].
~ D Kuang

#6 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 07 June 2006 - 09:36 PM

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.
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#7 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 08 June 2006 - 12:14 AM

[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

NoGray.com





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users