[erlang-questions] '--' BIF to be used with caution?

Richard O'Keefe ok@REDACTED
Fri Feb 13 02:12:35 CET 2009


I wrote:
>
> For teeny tiny lists, they are all too fast
> to measure reliably, which means that for teeny tiny lists
> there is no point in keeping the C code.
>
On 12 Feb 2009, at 11:37 pm, Hynek Vychodil wrote:
>
> Hundreds hares are wolf's death. Keep in mind that Erlang systems is  
> supposed to be soft real time in some application. There is latency  
> matter in those applications. If in one task you have to do hundreds  
> of '--' operations even with short lists you need do it in ns or us  
> times and BIF is worth solution there.

I'm not familiar with the "hundred hares" proverb and
am unable to grasp its meaning here.

*Are* there any tasks where hundreds of '--' on short lists
have to be done very fast?  Any tasks where, say, using bit
masks wouldn't be a better choice?

I avoid using --, so I decided to poke around in the OTP sources
to see what I could find.  There was roughly one -- every three
thousand lines. There are lots of uses of List -- [Elem],
which is linear time.  HiPE makes more use of -- than I expected;
anyone in the HiPE team care to comment?

For what it's worth,
a loop evaluating Xs \ Ys 100,000 times,
where Xs and Ys both had ten elements and did not intersect, took
4.3 micro-seconds per iteration using the native C-coded --
4.2 micro-seconds per iteration using a merge-based set difference
     written in Erlang, not C.
The machine was a 500MHz UltraSPARC II.

So the C version doesn't seem to have much advantage for small
lists either.  I'll grant that there probably is an advantage
for the case of List -- [Elem], but is that enough to justify
a C BIF?





More information about the erlang-questions mailing list