Timer:tc

Matthew Sackman matthew@REDACTED
Thu Aug 24 15:43:21 CEST 2006


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



More information about the erlang-questions mailing list