[erlang-questions] 2D Map Arrays

Ulf Wiger (TN/EAB) ulf.wiger@REDACTED
Mon Sep 11 12:56:48 CEST 2006


Richard Carlsson wrote:
> 
> Ulf Wiger wrote:
> > This looks awfully similar to the 'lines' module in jungerl.
> > Could you describe the main differences?
> 
> Noticeably faster, according to Dan's measurements.
> (I haven't looked at the code for the lines module myself.)

Hmm, yes, a 'replace' takes about 15 us in lines.erl compared
to ca 8 us in array.erl, and for 'get', the numbers were 7/13. 

Interestingly, 'from_list' (measured on a list of 1000 elements) 
was noticeably faster in lines.erl than in array.erl. I think 
this is because I have an optimized function for creating a large 
tree, rather than growing the tree as I go. The figures were 
238 us for 'lines' and 626 us for 'array'.

But here's the main difference (now that I've spend more than
15 seconds looking at array.erl): The 'lines' module supports
insert() and delete(), whereas array.erl doesn't.

While it would have been possible to optimize lines.erl 
slightly for nth() and replace() (not quite reaching the
speed of array.erl, but closing the gap somewhat) by using
tuples instead of lists as leafs, this would make append(),
insert() and delete() quite less appealing.

BR,
Ulf W




More information about the erlang-questions mailing list