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

Richard O'Keefe ok@REDACTED
Wed Feb 11 01:25:38 CET 2009

I asked why (--) could not be implemented in Erlang instead of C.

On 10 Feb 2009, at 9:44 pm, Hynek Vychodil wrote:
> It's easy, constants for serious amount |2|.

I am not sure how to interpret this.
Let's face it, *as currently implemented* -- is not
only inefficient, it can block scheduling for non-
trivial amounts of time.  So as things stand now,
fully informed programmers are unlikely to make very
much use of it, so in any program where the constant
factors are likely to make much difference, it is
_already_ so slow that something else should be done.
For example, I just measured some times:

681.69 msec, bag difference of unsorted lists using --
   0.64 msec, bag difference of sorted lists using own
              sorted list difference code in Erlang
  24.97 msec, bag difference of unsorted lists by
              sorting then using sorted list difference.

The one relying on a C coded -- is the slowest of them.

OK, so the lists were 10,000 elements long.  Make them
10 times smaller, and the times are
   5.24 msec unsorted then --
   0.08 msec presorted, use own Erlang
   1.63 msec unsorted, use sort then own Erlang.
Still the same conclusion: even coded in C, -- is too
slow to use with any lists that might be nontrivial.
So who cares about the constant factors in an operation
that you shouldn't be using?  Every time we move something
out of C into Erlang we simplify the trusted base.


More information about the erlang-questions mailing list