Iteration over lists

Roger Larsson <>
Fri Mar 17 16:02:11 CET 2006


On fredag 17 mars 2006 15.36, Bengt Kleberg wrote:
> On 2006-03-17 15:09, Emil Öberg (LN/EAB) wrote:
> > I don't think you can use timer:tc() to do the measuring here. You
> > need to measure cpu time, not elapsed. List comprehension will not
> > suspend (if I have understood the erts correct), but the rest will,
> > so it is natrual that it takes less real time. I used fprof with
>
> i do not understand. imho elapsed time is more important than cpu time.
>

Usually you can trust CPU time more. The OS might have decided to clean
up some memory for file accesses or suspended your process to run
other more important stuff. CPU time is the time actually spent in your
program. But... In Erlang garbage collection can happen any time...

My results varies wildly (R10B-10):

> iter:timeing( 100000 ).
recursion: 7153 true
revrecursion: 9523 true
mapfun: 18846 true
listcompr: 11853 true

recursion: 8717 true
revrecursion: 49129 true
mapfun: 35269 true
listcompr: 12383 true

recursion: 13909 true
revrecursion: 12137 true
mapfun: 28469 true
listcompr: 11351 true

This could be due to several reasons:
- I am running an AMD in Cool'nQuiet
 (will it take time to adjust CPU frequency?)
- When garbage collection happens.
- When erlang is scheduled away from the CPU

/RogerL



More information about the erlang-questions mailing list