Timer:tc
Ulf Wiger (TN/EAB)
ulf.wiger@REDACTED
Mon Aug 28 10:36:43 CEST 2006
I usually write a benchmark loop allowing me to measure over enough
iterations to bring the times into at least hundreds of milliseconds or
seconds. Then I repeat several times and take the lowest value (least
amount of interference). Then (of course), I divide the time by the
number of iterations.
I also usually repeat the procedure with an empty loop, and calculate
the difference.
It's reasonable to spawn a new process for each iteration, to make sure
that the measurement doesn't start with lots of garbage on the heap.
BR,
Ulf W
> -----Original Message-----
> From: owner-erlang-questions@REDACTED
> [mailto:owner-erlang-questions@REDACTED] On Behalf Of
> Matthew Sackman
> Sent: den 28 augusti 2006 10:06
> To: erlang-questions@REDACTED
> Subject: Re: Timer:tc
>
> On Mon, Aug 28, 2006 at 11:52:26AM +0800, lang er wrote:
> > So why:
> > Erlang (BEAM) emulator version 5.5 [source] [async-threads:0] [hipe]
> >
> > Eshell V5.5 (abort with ^G)
> > 1> timer:tc(count_chars,file, ["gc.txt"]).
> > {1173,116}
>
> File has to be fetched from harddisc, so will cost time.
>
> > 2> timer:tc(count_chars,file, ["gc.txt"]).
> > {375,116}
>
> Now file is cached in RAM by OS so access is much faster.
>
> > 3> T1 = erlang:now(),
> > 3> count_chars:file("gc.txt"),
> > 3> T2 = erlang:now(),
> > 3> Time = timer:now_diff(T2, T1).
> > 464
>
> Oh. Unknown - someone who knows Erlang much better than I
> will have to answer that. OTOH, 464 isn't much higher than
> 375 - these are microseconds. My guess is that it's
> experimental variance - how repeatable are these numbers? Do
> it 10 times both methods, both orderings and average. For
> most functions, the cost of the function itself will be much
> greater than the cost of the function invocation so the
> expense of the apply in :tc/3 won't feature for any function
> that does any "real" work(!)
>
> Matthew
> --
> Matthew Sackman
>
> BOFH excuse #259:
> Someone's tie is caught in the printer, and if anything else
> gets printed, he'll be in it too.
>
More information about the erlang-questions
mailing list