Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why golang is slower than scala? [closed]

Tags:

In this test, we can see that the performance of golang is sometimes much slower than scala. In my opinion, since the code of golang is compiled directly to c/c++ compatible binary code, while the code of scala is compiled to JVM byte code, golang should have much better performance, especially in these computation-intensive algorithm the benchmark did. Is my understanding incorrect?

http://benchmarksgame.alioth.debian.org/u64/chartvs.php?r=eNoljskRAEEIAlPCA48ozD%2Bb1dkX1UIhzELXeGcih5BqXeksDvbs8Vgi9HFr23iGiD82SgxJqRWkKNctgkMVUfwlHXnZWDkut%2BMK1nGawoYeDLlYQ8eLG1tvF91Dd8NVGm4sBfGaYo0Pok0rWQ%3D%3D&m=eNozMFFwSU1WMDIwNFYoNTNRyAMAIvoEBA%3D%3D&w=eNpLz%2FcvTk7MSQQADkoDKg%3D%3D

like image 818
Tyr Avatar asked Jan 02 '14 02:01

Tyr


People also ask

Is Scala faster than Golang?

If you know Java and like working with data, then Scala is a better option, but if you want to learn a language fast with a broader application, then Golang is the winner.

Why is Golang slow?

Basically, it comes down to language complexity. There is no question that Rust is much more complex a language than Go. This makes it harder to learn.

Why is Golang fast compared to other languages?

Programs written in Golang are typically much faster than those written in interpreted languages like Python, Ruby or JavaScript because they don't need to be converted before running – this process also known as “interpretation”.

Is Golang slower than C?

Speed comparison of Go vs. C. Compiled Go code is generally slower than C executables.


1 Answers

Here's what I think's going on in the four benchmarks where the go solutions are the slowest compared to the scala solutions.

  1. mandelbrot: the scala implementation has its internal loop unrolled one time. It may be also that the JVM can vectorise the calculation like this, which I think the go compiler doesn't yet do. This is good manual optimisation plus better JVM support for speeding arithmetic.
  2. regex-dna: the scala implementation isn't doing what the benchmark requires: it's asked to """(one pattern at a time) match-replace the pattern in the redirect file, and record the sequence length""" but it's just calculating the length and printing that. The go version does the match-replace so is slower.
  3. k-nucleotide: the scala implementation has been optimised by using bit-twiddling to pack nucleotides into a long rather than use chars. It's a good optimisation that could also be applied to the Go code.
  4. binary-trees: this tests gc performance by filling RAM. It's true that java gc is much faster than the go gc, but the argument for this not being the top priority for go is that usually one can avoid gc in real programs by not producing garbage in the first place.
like image 72
Paul Hankin Avatar answered Sep 21 '22 05:09

Paul Hankin