Hacker News new | ask | show | jobs
by adamdegas 1032 days ago
The Computer Language Benchmarks Game has C++ outperforming Rust by around 10% for most benchmarks. Binary trees is 13% faster in C++, and it's not the best C++ binary tree implementation I've seen. k-nucleotide is 32% faster in C++. Rust wins on a few benchmarks like regex-redux, which is a pointless benchmark as they're both just benchmarking the PCRE2 C library, so it's really a C benchmark.

> because C++ makes it laughably easy to write incorrect code

I was going to ask how much you actually program in C++, but I found a past comment of yours:

> I frankly don't understand C++ well enough to fully judge about all of this

2 comments

> Rust wins on a few benchmarks like regex-redux, which is a pointless benchmark as they're both just benchmarking the PCRE2 C library, so it's really a C benchmark.

The Rust #1 through #6 entries use the regex crate, which is pure-Rust. Rust #7[rust7] (which is not shown in the main table or in the summary, only in the "unsafe" table[detail]) uses PCRE2, and it is interestingly also faster than the C impl that uses PCRE2[c-regex] as well (by a tiny amount). C++ #6[cpp6], which appears ahead of Rust #6 in the summary table (but isn't shown in the comparison page)[comp], also uses PCRE2 and is closer to Rust #7.

[comp]: https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

[detail]: https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

[rust7]: https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

[c-regex]: https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

[cpp6]: https://benchmarksgame-team.pages.debian.net/benchmarksgame/...

I mean, it's outperforming C as well in that particular benchmark.

Lies, damn lies, and benchmarks?

I can at least say, the performance difference between C, C++, and Rust, is splitting hairs.

If you want to write something performant, low level, with predictable timing, all three will work.

I'm spending a lot of time building projects with Rust & C++ these days. The issue/tradoff isn't performance with C++, but that C++ is better for writing unsafe code than Rust.

https://www.p99conf.io/2022/09/07/uninitialized-memory-unsaf...