erlang:tc() returning 1 (Was: Re: Iteration over lists)

Roger Larsson roger.larsson@REDACTED
Fri Mar 17 17:13:30 CET 2006


On fredag 17 mars 2006 14.58, you wrote:
> Hi,
>
> For reference, my compiler does cheat :-)
>
> (emacs@REDACTED)9> iter:timeing(100000).
> recursion: 1 true
> revrecursion: 15998 true
> mapfun: 15000 true
> listcompr: 1 true


I think something is not correct here... I have seen this too... (Linux)
So I did a test program

lists:map(fun (_) ->timer:tc(erlang, is_boolean, [1]) end, lists:seq(1, 100)).
[{7,false},
 {5,false},
 {5,false},
 {4,false},
 {4,false},
 {4,false},
 {5,false},
 {5,false},
 {5,false},
 {5,false},
 {5,false},
 {5,false},
 {5,false},
 {5,false},
 {5,false},
 {4,false},
 {5,false},
 {5,false},
 {4,false},
 {5,false},
 {5,false},
 {26,false},
 {5,false},
 {5,false},   
- - -

The actual time for this function is probably 4-5 us.
First time (7 us) is always longer and one (26 us) [something
externally happened - erlang runtime or system]

But I usually do not get 1 us, but once I did.

[{6,false},
 {5,false},
 {5,false},
 {5,false},
 {5,false},
 {5,false},
 {1,false},
 {1,false},
 {1,false},
 {1,false},
 {1,false},
 {1,false},
 {1,false},
 {1,false},
 {1,false},
 {1,false},
 - - -

>From the description of
erlang:now() "It is also guaranteed that subsequent calls to this BIF returns 
continuously increasing values"
I wonder if we are seeing a case where system time is going backwards and
erlang:now is handling this by returning values increasing by one until real
time has caught up. [but it takes too long time several calls... should not be
likely is something wrong in the code - wrapping?]

/RogerL



More information about the erlang-questions mailing list