Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 522
yetanothercoder Avatar asked Nov 29 '12 15:11

yetanothercoder


People also ask

Is Erlang better than Java?

Erlang processes are more akin to Java objects in terms of their abstraction, and are often used as such by Erlang programmers. The big difference then is that they can run concurrently. @adam Actually Erlang processes are the only true objects as the inventor of OOP inagined them.

Is Erlang fast?

A native-code compiler is available, and according to numerical benchmarks, it makes Erlang programs faster than Ruby, Perl, and PHP, albeit slower than Java and JavaScript.


1 Answers

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.

like image 94
npe Avatar answered Oct 29 '22 20:10

npe