[erlang-questions] Performance of the append/reverse idiom

Joe Armstrong <>
Mon Jul 16 09:53:06 CEST 2007


Is reverse a bottleneck?

Very rarely.

The are some *extremely* rare cases where people write code to handle
both reversed
and non-reverse lists (I think the library routines for sort remember
if the current
list being sorted is in normal or reversed order) but this is only useful when
you're interested in making a tiny gain in efficiency (it also make the code
a  mess to read).

The most common bottleneck are in the I/O system. Parsing inputs (in
any language)
is always a slow - other bottleneck are usually in the process
structure - using a centralized server that serializes everything can
make nasty bottlenecks.

/Joe


On 7/16/07, Christopher Baus <> wrote:
> Hi,
>
> I'm still going through Joe's book, but as a C/C++ hack, I can't help
> but have some reservations about performance.  One common idiom is to
> append to the front of a list and then reverse the list when the append
> is complete.  I assume this a O(n) operation.  Is it common for reverse
> to be a bottleneck in many applications?
>
> Thanks,
>
> Chris
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list