Gossamer Forum
Home : General : Perl Programming :

Calculating load time

Quote Reply
Calculating load time
I would like to calculate load time of the script right down to the 1/10 th of a second or even 1/1000th of a second.

I currently use
$start_time = time;

at the start of the script

and

$elapsed_time = (time - $start_time);

at the end of the script but this only records it down to the second.

Any ideas?

Quote Reply
Re: Calculating load time In reply to
"Use" Benchmark.pm.

Search the support forums for Benchmark.

Regards,

Eliot Lee
Quote Reply
Re: Calculating load time In reply to
Install Time::HiRes module and add `use Time::HiRes qw/time/;` to your code. The time function will now be much more precise.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Calculating load time In reply to
Is thereany way to get search timing down to thousandths of a second?

Paul Wilson. Shocked
(Dont blame me if I'm wrong!)
Quote Reply
Re: Calculating load time In reply to
Does the module Alex suggested round to the thousandth of a second?

Isn't the format something like this:
.03

Robert Blackstone
Webmaster of Scato Search
http://www.scato.com
Quote Reply
Re: Calculating load time In reply to
Yes the HiRes module gives something like 1.23 (see it in action at audio-grabber.com)



Paul Wilson. Shocked
(Dont blame me if I'm wrong!)
Quote Reply
Re: Calculating load time In reply to
Hi,

It actually goes much more detailed then that, I just round it off in nph-build.cgi. Try:

perl -MTime::HiRes=time -e 'print time'

which has up to six decimal points on my system.

Cheers,

Alex

--
Gossamer Threads Inc.
Quote Reply
Re: Calculating load time In reply to
Oh excellent....

I wanted more accuracy and didn't realise it was being rounded up.



Paul Wilson. Shocked
(Dont blame me if I'm wrong!)
Quote Reply
Re: Calculating load time In reply to
Thank you, helped a lot,

I now get things like 0.034787797927856 seconds instead of 1 second which makes a bid difference.

Thanks Alex.

Quote Reply
Re: Calculating load time In reply to
Ah yes....

I need to change "%.2f" don't I..to something like "%.4f" and it uses 4 decimal places.

Thanks!

Paul Wilson.
NEW http://www.wiredon.net
Quote Reply
Re: Calculating load time In reply to
can't you just use times()?

times() give you past milli seconds also.. and you don't have to install anything

BEGIN {
my $start = times();
}
END {
print "Time: ", (times() - $start), " seconds\n";
}

just put that at the beginning of your code..

Jerry Su
widgetz sucks
Quote Reply
Re: Calculating load time In reply to
Oh right I didnt know that.....

I have it setup now so Im not going to change it, but Ill know for the future.....

Thanks.

Paul Wilson.
http://www.wiredon.net