[erlang-questions] lists bifs vs list comprehensions

Kostis Sagonas <>
Thu Apr 5 17:29:43 CEST 2012


On 04/05/12 17:45, Martin Dimitrov wrote:
> Hello,
>
> 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.

A bit unrelated to your actual question, but AFAIK tidier does not 
transform any lists:foreach/2 to a list comprehension. (If you have such 
a case, I am definitely interested in seeing this.)

Instead it transforms lists:filter/2 to list comprehensions.

Kostis



More information about the erlang-questions mailing list