4 ms·
> Rust applications are sometimes (often?) slower than comparable C applications Could you cite some examples? There are plenty of counter-examples - ripgrep
by nindalf 2y ago
> Rust applications are sometimes (often?) slower than comparable C applications
Could you cite some examples? There are plenty of counter-examples
- ripgrep is 5-10x faster than grep (https://github.com/BurntSushi/ripgrep/blob/962d47e6a1208cf2187cd34c2a7f6cf32e2a4903/benchsuite/runs/2022-12-16-archlinux-duff/summary https://github.com/BurntSushi/ripgrep/blob/962d47e6a1208cf21...). There's a reason ripgrep is embedded within VS Code to power search.
- Memory-safe implementations of PNG (png, zune-png, wuffs) now dramatically outperform memory-unsafe ones (libpng, spng, stb_image) when decoding images. (https://www.reddit.com/r/rust/comments/1ha7uyi/memorysafe_png_decoders_now_vastly_outperform_c/ https://www.reddit.com/r/rust/comments/1ha7uyi/memorysafe_pn...)
- The Rust implementation of GNU Coreutils compares favourably in performance. For example, uutils/sort outperforms coreutils/sort by 6x while working on every mainstream OS - Linux, FreeBSD, NetBSD, OpenBSD, Illumos, Redox, Android, macOS, and Windows.(https://lwn.net/Articles/1007907/ https://lwn.net/Articles/1007907/)
- Android rewrote their IPC code (Binder) from C to Rust. The Rust version is within +- 1-2% of the C version (https://www.phoronix.com/news/Google-Linux-Binder-In-Rust https://www.phoronix.com/news/Google-Linux-Binder-In-Rust).
- rustls outperforms OpenSSL and BoringSSL (https://www.memorysafety.org/blog/rustls-performance-outperforms/ https://www.memorysafety.org/blog/rustls-performance-outperf...)
- zlib-rs is the fastest implementation of zlib (https://www.phoronix.com/news/Zlib-rs-0.4.2 https://www.phoronix.com/news/Zlib-rs-0.4.2)
- Advent of Code - The one C example I saw executed the first 10 days of 2024 in 36ms (https://www.reddit.com/r/adventofcode/comments/1hbcyhz/comment/m1fapgz/ https://www.reddit.com/r/adventofcode/comments/1hbcyhz/comme...), while my idiomatic Rust solutions (https://github.com/nindalf/advent https://github.com/nindalf/advent) took 10.1ms. I'm not even that good, there are Rust solutions 10x faster than mine - https://github.com/maneatingape/advent-of-code-rust https://github.com/maneatingape/advent-of-code-rust.
- I don't consider the benchmarks game a worthwhile comparison because they're only writing assembly, but Rust and C are comparable in speed (https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/rust-gcc.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...)
So yes, I'm surprised by your claim of C programs "often" outperforming comparable Rust programs, but I'd be interested to know if even the "sometimes" is true. Please share if you've found any.
The other claims are questionable as well, but this one was the most easily disproven.
- igouy 2y ago> I don't consider the benchmarks game a worthwhile comparison because they're only writing assembly Do you mean the "Rust" programs are assembly? https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/spectralnorm-rust-1.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
- nindalf 2y ago> Do you mean No I don't mean. I said what I said. If you click the C program right next to the Rust program for "spectral-norm" you get the equally unreadable - https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/spectralnorm-gcc-6.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
- igouy 2y agoDo you mean the "Rust" programs are assembly but the "C" programs forced them to be that way? https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/spectralnorm-gcc-8.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
- nindalf 2y agoNo I don't mean. It is possible to write idiomatic Rust and C. It is possible to write assembly in the form of Rust and C. In both cases, they're comparable in performance. But leaving toy programs like Benchmarks Game and AoC aside, I gave 6 examples of Rust outperforming C. Do you have any examples of C outperforming Rust?
- igouy 2y ago> Do you have any examples of C outperforming Rust? I don't have a pony in that race. > uutils/sort outperforms coreutils/sort by 6x "He used the hyperfine command-line benchmarking tool to run a test ten times; sorting a text file containing all of Shakespeare's works to see which implementation was faster. The first time he performed the test, he used a debug build of the Rust version of sort. In that demo, Rust's version was 1.45x faster than the GNU version. Then he ran the test again using a non-debug version, which showed the Rust version performing the test six times faster than GNU's implementation." Might it be that a new implementation in C would also have been faster?