Jump to content

Recommended Posts

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\" /]
Link to comment
https://forums.phpfreaks.com/topic/11300-page-execution-time/
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/11300-page-execution-time/#findComment-42310
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/11300-page-execution-time/#findComment-42951
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/11300-page-execution-time/#findComment-42971
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.