Introduction

This page compares the efficiency of different languages and their compiler/interpreter (C, Java, OCaml, Rust). It takes some contributions from the The Computer Language Benchmark Game, but instead of comparing the skill of different programmers, and the use of more or less tricky gcc features (parralel pragma, near assembly SSE/MMX opcodes...), each program use nearly the same logic (excepted with explicit comments), and no CPU opcode or threads. The binarytrees test is executed twice. Once with the default allocator (malloc, new...), and a second time with an ad'hoc allocator when possible or similar optimisation.

C, OCaml and Python have a version of spectral_norm that uses the optimised LAPACK library (using Numpy for Python). The benchmark ends comparing LAPACK with itself, then it was not applied to other languages.

Note : 2 benchmarks from the Computer Language Benchmark Game have been excluded, since they won't compare both compilers, but different libraries (gmp vs. zarith, or 2 regex libraries).

The code and the comparison

NOTA

C code is compiled with gcc -O3.

Java code is compiled with javac and run with java

OCaml code is compiled with ocamlopt -O3 -unsafe -inline-max-depth 10.

Rust code is compiled with rustc -C opt-level=3.

All exemple have been run in a Debian environment on a Intel(R) Xeon(R) CPU D-1531, with the hyperfine command.

The code is copyrighted see the revised BSD license.