in reply to Re: Which is faster ?
in thread Which is faster ?

Thanks for the helpful docs.
But I prefer measuring my program's time by:
my $t1 = time(); ... ...somecode... ... my $t2 = time(); print "It took ".(int(($t2-$t1)/3600)).':'.(int((($t2-$t1) % 3600)/60) +).'.'.(int(($t2-$t1) % 60))."\n";

And outputing from every func() all its main variables.

Replies are listed 'Best First'.
Re^3: Which is faster ?
by kyle (Abbot) on Jun 04, 2008 at 17:53 UTC

    One problem with that is it doesn't really tell you how much of that time is spent in your program and how much is spent by your program waiting (for a database, or the network, or a disk drive, or another program getting a time slice, etc.). There's not much point in trying to speed up a piece of code that does nothing but wait for something out of your control.

    If you still like that style of timing anyway, you could get better results with Time::HiRes.

Re^3: Which is faster ?
by starbolin (Hermit) on Jun 04, 2008 at 17:56 UTC

    Apples and oranges. Profiling is not about timing; profiling tells you 'where' your code spends it's time. Where your code 'is' useful is timing long runs of linear code whereas the Benchmark module is useful for snippets of code and getting at the internals of subroutines without measuring the subroutine call itself. As to just storing time(), actually I've done that myself on occasion but usually I use the Time::HiRes module.


    s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}