Hi everyone, I'd like to share a success story of one of my co-workers, who beat C-performance in his first week of learning Rust.
This shows, to me, the great potential rust has as a language: high-level programming, with great low-level performance, accessible to newcomers.
TL;DR: prototypes and benchmark timings here
Background:
My coworker is optimising scripts for a bioinformatics web-service our institute hosts (CRISPR AnalyzeR ). It is currently written in a mix of R and Perl, and some parts are very slow not as fast as we'd like.
On the tram to work, he mentioned that he was rewriting a particularly slow Perl script (0m45.006s on the benchmark file) in C, and had gotten it down to 0m4.409s in low-level C, an admirable 10x speedup.
We talked about the fact that it was quite hard to get back down in all the nitty-gritty pointer handling of C, which was my cue to preach the Rust Gospel: productive high-level concepts, memory safe and fast! (with easy transition to multi-threading for even more performance later!)
I sent him some links to cargo and the rust book, and he said he'd give Rust a try.
The next morning he had an initial working version in Rust, coming in at 0m14.334s.
Now, before we go into the performance, just the fact that he could get a working version in 24 hours is a good sign in itself. The script iterates over a biological data file (fastQ), which has a multi-line record structure. If the record identifier matches a regex, it is copied to the output file. Quite simple all in all, but still, this means my colleague got himself up to speed in:
- The rust language,
- The cargo ecosystem, and
- The regex crate
all in 24 hours. So much for Rust being "too hard to be adopted" ![]()
We were both surprised that rust was so much slower than C, and checked the usual "compiled with --release ?" (yes, it was).
Then I noticed that we were spending a whopping 10s of our 14 seconds in system time, which caused me to look at the code.
Two inserts of std::io::BufWriter later, and we're suddenly at 0m3.866s, beating C by 500 ms! (i.e. 11,8%)
Cue great enthusiasm at my colleague's department, and another 2 people interested in Rust.
All in all, quite the success ![]()
P.S. and if the perf story isn't good enough by itself; when I cloned the rust version, I did "cargo run --release" and everything magically worked, downloading dependencies and everything.
When I ran the C version with "make; ./bin/prototype", all I got was "SEGFAULT" ![]()