Timer:tc

lang er erlangist@REDACTED
Mon Aug 28 05:52:26 CEST 2006


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}
2> timer:tc(count_chars,file, ["gc.txt"]).
{375,116}
3> T1 = erlang:now(),
3> count_chars:file("gc.txt"),
3> T2 = erlang:now(),
3> Time = timer:now_diff(T2, T1).
464
4>

count_chars module is one of examples on Erlang.org

2006/8/24, Matthew Sackman <matthew@REDACTED>:
>
> On Thu, Aug 24, 2006 at 12:55:07PM +0100, Nebmo wrote:
> > What is the difference between:
> >
> > 1:
> > {Time,_} = timer:tc(mod,fun,[arg]),
> >
> > 2:
> > T1 = erlang:now(),
> > mod:fun(arg),
> > T2 = erlang:now(),
> > Time = timer:now_diff(T2, T1),
>
> locate timer.erl
> /usr/lib/erlang/lib/stdlib-1.14/src/timer.erl
> ...
> tc(M, F, A) ->
>     Before = erlang:now(),
>     Val = (catch apply(M, F, A)),
>     After = erlang:now(),
>     {now_diff(After, Before), Val}.
>
> It'll be many times slower because of the apply.
> http://www.erlang.org/doc/doc-5.5/doc/efficiency_guide/functions.html
>
> Matthew
> --
> Matthew Sackman
>
> BOFH excuse #438:
> sticky bit has come loose
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20060828/fc599913/attachment.htm>


More information about the erlang-questions mailing list