v/examples/1brc
2025-03-13 19:51:51 +02:00
..
make-samples examples: add a solution to the "1 Billion Row Challenge" (#23458) 2025-01-15 09:09:11 +02:00
solution tools: cleanup entries from the hardcoded skip_files list in common.v (used by v test, v test-self etc); use the new // vtest build: syntax to mark the tests instead (#23918) 2025-03-13 19:51:51 +02:00
README.md examples: add a solution to the "1 Billion Row Challenge" (#23458) 2025-01-15 09:09:11 +02:00

1 Billion Row Challenge (1BRC)

A solution to the 1 Billion Row Challenge, written in the V programming language.

Read more about the challenge here: https://www.morling.dev/blog/one-billion-row-challenge/

Running instructions

Suggested compiler options for performance:

v -cc gcc -prod -cflags "-std=c17 -march=native -mtune=native" .

Step 1: Create a measurements file

Compile and run make-samples to create the sample file.

cd make-samples
v -cc gcc -prod -cflags "-std=c17 -march=native -mtune=native" .
./make-samples 1000000000 > ~/measurements.txt

NOTE: If you create a billion rows, the file will be about 12GB!

Step 2: Run (and time) the solution

cd solution
v -cc gcc -prod -cflags "-std=c17 -march=native -mtune=native" .
./solution ~/measurements.txt

You can time the solution using v time:

v time ./solution ~/measurements.txt

By default, the solution runs in a single thread. If you want to run parallel processing, use the -n parameter, for example, to run with 8 threads:

./solution -n 8 ~/measurements.txt

On Linux, to run one thread per core, use

./solution -n $(nproc) ~/measurements.txt

Step 3: Improve upon the solution

Make changes that improve the performance and submit them. Let's show off what is possible in V!