Why is Erlang slower than Java on all these small math benchmarks?

yetanothercoder picture yetanothercoder · Nov 29, 2012 · Viewed 22.1k times · Source

While considering alternatives for Java for a distributed/concurrent/failover/scalable backend environment I discovered Erlang. I've spent some time on books and articles where nearly all of them (even Java addicted guys) says that Erlang is a better choice in such environments, as many useful things are out of the box in a less error prone way.

I was sure that Erlang is faster in most cases mainly because of a different garbage collection strategy (per process), absence of shared state (b/w threads and processes) and more compact data types. But I was very surprised when I found comparisons of Erlang vs Java math samples where Erlang is slower by several orders, e.g. from x10 to x100.

Even on concurrent tasks, both on several cores and a single one.

What's the reasons for that? These answers came to mind:

  • Usage of Java primitives (=> no heap/gc) on most of the tasks
  • Same number of threads in Java code and Erlang processes so the actor model has no advantage here
  • Or just that Java is statically typed, while Erlang is not
  • Something else?

If that's because these are very specific math algorithms, can anybody show more real/practice performance tests?

UPDATE: I've got the answers so far summarizing that Erlang is not the right tool for such specific "fast Java case", but the thing that is unclear to me - what's the main reason for such Erlang inefficiency here: dynamic typing, GC or poor native compiling?

Answer

npe picture npe · Nov 29, 2012

Erlang was not built for math. It was built with communication, parallel processing and scalability in mind, so testing it for math tasks is a bit like testing if your jackhammer gives you refreshing massage experience.

That said, let's offtop a little:
If you want Erlang-style programming in JVM, take a look at Scala Actors or Akka framework or Vert.x.