[erlang-questions] lists bifs vs list comprehensions

Martin Dimitrov <>
Thu Apr 5 16:45:42 CEST 2012


Several days ago I used the tidier tool on a module I wrote and I
noticed that it translates lists:foreach/2 and lists:map/2 to list
comprehensions. I did some tests and came to the conclusion that list
comprehension is executed faster than lists:map/2. Also for lists less
than 50 000 items lists:foreach/2 is again slower than list
comprehension. But for bigger lists - it is the reverse.

Why is that so? I thought lists:map/2 and list comprehensions are
compiled to equivalent code.

Many thanks.


More information about the erlang-questions mailing list