Performance comparision among programming laguages

I created a program with single-thread simple algorithm that calculates prime numbers up to 100 million. I measured the execution time and the maximum used memory size. The source code is here.
Lang. Time (sec) Maximum used physical memory (MiB) Container for calculated prime numbers Remarks My impression
C 12.6 24.1 Fixed size array gcc 8.3.0
Optimization -O3
-
C++ 64.8 36.0 std::vector gcc 7.3.0
No optimization (build with -O0)
-
C++ 12.7 36.0 std::vector gcc 7.3.0
Optimization (build with -O3)
Optimzation is very effective. Memory usage is also less.
JAVA 17.2 215.5 ArrayList OpenJDK 10.0.2 Execution time about 1.5 times longer than C/C++. Roughly consistent with previous experience.
Kotlin 17.2 236.5 List Kotlin 1.3.61 Equivalent to Java. Not a bad choice considering the ease of writing code.
Scala 20.1 2023.0 mutable.ArrayBuffer Scala 2.11.12 In terms of speed, it is only slightly inferior to Java, but its memory usage is about 10 times that of Java and nearly 100 times that of C++.
Golang 49.2 136.2 slice go1.11.6 It is not faster than I expected. The memory usage is also about half that of Java, so this result alone may not be enough to make it halfway useful.
Node.js 23.2 184.8 Array v8.10.0 Comparable to Java and Scala. Faster than expected. Not too much memory usage.
PHP 151.2 196.7 array PHP 7.2.10 There doesn't seem to be anything particularly good about it. I don't think it's a language that I would force myself to use.
Python 451.8 3235.2 list 2.7 Very slow and memory usage is so bad. But I don't hate. I really should use NumPy or something like that for this kind of use. I'd like to try it with numba at a later date.
Python3 592.8 238.3 list 3.6.7 Memory usage is one half of that of Python2. However, the performance degraded.

No comments:

Post a Comment