Timer:tc
Matthew Sackman
matthew@REDACTED
Mon Aug 28 10:05:45 CEST 2006
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