Today, let’s run some benchmark and compare performance of the same program written in C++
vs Rust
vs Go
. We try our best to isolate noise from factors other than the difference in languages. As with any benchmark, however, the result is to be taken with grain of salt — no single benchmark can truly compare the performance of two different languages.
Program
The program we will compare is gunzip
that decompresses .gz
files. There are different implementations of gunzip
, such as GNU gzip written in C
, zlib written in C
, miniz written in C
, flate2-rs written in Rust
and gzip in Go
.
However, we can’t accurately benchmark two languages unless one is a direct port of another, as this introduces noise from possibly different implementations.
For that reason, we will choose the following three
- gunzip written in
Rust
- cpp_gunzip, a direct port of above written in
C++
- go_gunzip, a direct port of above written in
Go
Minimizing noise
There is still one issue — use of external library. They rely on a third-party library for computing CRC32
checksum, which takes significant time within decompression. In particular, gunzip relies on crc32fast crate, cpp_gunzip can link against either zlib or FastCrc32, and go_gunzip relies on Go
standard crc32 library. Luckily, all of them support a multi-thread option that runs CRC32
checksum on a separate thread…