Akarsh Gopal

1BRC

The One Billion Row Challenge, in C and Rust.

Role
Personal project
Started
Sep 2026
Stack
C, Rust
Machine
Apple M1 Pro, 16 GB
Links
Source on GitHub

What it is

26.9 slatest C time for a billion rows.8.7×faster than my first C pass.

Practice in performance-oriented programming on the One Billion Row Challenge: read a billion rows of city temperature readings and print the min, mean and max for every city, as fast as possible. I had no professional experience in either language, so this is a way to learn both.

Rules

  • No external library dependencies.
  • The computation happens at runtime; nothing is baked into the binary.
  • No LLM-written code: every character in the codebase is hand-written.

Progress

  1. Baseline: wc over the file46.7 s
  2. C, pass 1 (unsorted output)3:55
  3. Rust, pass 12:39
  4. C, pass 2: fewer mallocs, sorted output1:51
  5. C: chunked fread() instead of fgets()50.4 s
  6. C: linear probing, unrolled parsing26.9 s
Total wall-clock time on an Apple M1 Pro with 16 GB, from the repo’s notes. Shorter is better.

Lessons

A first from-scratch hash map in C, and a first string merge sort on its keys. The basics of Rust, and first-hand ownership and borrowing; writing the C version first and then the Rust one made it stick. The common bugs were the classic ones: off-by-one errors, string terminators, out-of-bounds access and memory corruption.