Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Finding script times using microtime()
Old 12-14-2007, 07:51 PM Finding script times using microtime()
Extreme Talker

Posts: 238
Location: United States
Trades: 0
I sometimes use microtime() to see how fast parts of my script are running. It is usually something along the lines of this:
PHP Code:
$start microtime(true);

// code block

$time microtime(true) - $start;
echo 
'<p>',round($time4),' seconds.</p>'
The weird thing is that sometimes when I view the page I will get negative times, like -0.1373, and other times I get positive times, like 0.095. This occurs just from simple browsing and refreshing, and without changing the code. Does anyone have any clues as to why this might be happening?
__________________
The interlocking pieces of web development: usability, performance, accessibility, and standards.
frost is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-14-2007, 10:56 PM Re: Finding script times using microtime()
JeremyMiller's Avatar
WT Moderator

Posts: 1,712
Name: Jeremy Miller
Location: Las Vegas, NV
Trades: 0
If the script executes too quickly, then you run into issues of accuracy. For instance, a computer doesn't do so hot storing 10^(-100000000000000000) and will cause you to get a negative where you ought to get a positive (for the mathematically challenged, that number IS positive -- it's the exponent which is negative). So, if you're trying to measure a script's speed which executes faster than .001 seconds, you'll have such weird issues.
__________________
Jeremy Miller

Please login or register to view this content. Registration is FREE
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 12-16-2007, 09:11 AM Re: Finding script times using microtime()
Extreme Talker

Posts: 238
Location: United States
Trades: 0
Heh. I think the problem was that I was using PHP 5 locally, and I forgot that I still had PHP 4 on the host which I was working on. I don't think there was a bool parameter in PHP 4.
__________________
The interlocking pieces of web development: usability, performance, accessibility, and standards.
frost is offline
Reply With Quote
View Public Profile
 
Old 12-16-2007, 09:29 AM Re: Finding script times using microtime()
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
[QUOTE]I don't think there was a bool parameter in PHP 4.[QUOTE]
True, it was added in PHP5.

If you want to profile your application, I recomand you Xdebug, if you can install it.
Look at this thread: http://www.webmaster-talk.com/php-fo...tml#post466576
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Finding script times using microtime()
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.16476 seconds with 12 queries