Skip to main content

Tag: Rust

Comparing speed of some fast languages

To get more familiar with Rust, I’ve lately been revisting last year’s Advent of Code problems, which I did in Go last December. My Go solution solution for Day 5 uses brute-force and is not very clever, but runs fast enough in Go (under 6 minutes). The Rust equivalent runs in 1/3 less time, and I was wondering how other languages would fare. The results might surprise you.

I ended up writing the solution in Rust, Zig, and C, in addition to the original Go solution.

Looking at Zig

I finally took some time this weekend to look at Zig, and I am very impressed. It’s a fairly low-level language, but could be appropriate for some performance-critical data science use cases. Based on an initial test, it is twice as fast as Rust, which is about 50% faster than Go. And it appears to be faster than C, which I find puzzling.

To explore the language, I rewrote a naive and computationally intensive brute-force solution to day 5 of last year’s Advent of Code. My non-sophisticated solution took 5:40 in Go for both parts, fast enough that I didn’t bother finding a more streamlined solution (which would have been necessary in Python). For comparison, I also rewrote the same solution in Rust and C.