Take the 2-minute tour ×

I see that Erlang Efficiency User's Guide Section 5.3 recommends leaving the non-flat list as it is when being used as an iolist because the penalty of non-flattening is smaller than flattening. Is there any quantitative example of the speed difference?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

When a deep list contains n elements, then performing lists:flatten on it will require Θ(n) time, and worse, Θ(n) memory allocations. How slow that is on your machine is a function of many variables; measure and ye shall know.

share|improve this answer
Thanks for the down-to-earth explanation. –  jj1bdx Mar 16 '12 at 15:39
add comment

Your Answer


