[erlang-questions] foldl vs foldr and ++
Tue Jan 14 12:41:29 CET 2014
I tweaked your module to run via escript (just adding a simple main/1 and
printing out the results of timer:tc), and I see a bit gap between foldl
and foldr, whilst the hand coded version based on lists:reverse/1 is plenty
t4@REDACTED:test $ escript lr.beam 10000000
t4@REDACTED:test $ evm info
R16B03 compiled for x86_64-apple-darwin11.4.2, 64bit
On Friday, 11 May 2012 10:27:29 UTC+1, Ulf Wiger wrote:
> On 11 May 2012, at 04:02, Richard O'Keefe wrote:
> > This can be written more efficiently, but it's best of all
> > just not to reverse the string in the first place. Keep
> > the code at a level where you can see what's going on well
> > enough to spot the really _big_ efficiency gains.
> And this is of course the really important difference between
> foldr() and foldl():
> - in which order do you want to process the list?
> - if you build a list in the accumulator, in which order do you want it?
> For most practical purposes, one should assume that they
> both both do their job efficiently.
> Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.
> erlang-questions mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions