|
| 1 | +# 1 Billion Row Challenge (1BRC) |
| 2 | + |
| 3 | +A solution to the [1 Billion Row Challenge](https://www.morling.dev/blog/one-billion-row-challenge/), |
| 4 | +written in [the V programming language](https://vlang.io/). |
| 5 | + |
| 6 | +Read more about the challenge here: https://www.morling.dev/blog/one-billion-row-challenge/ |
| 7 | + |
| 8 | + |
| 9 | +## Running instructions |
| 10 | + |
| 11 | +Suggested compiler options for performance: |
| 12 | + |
| 13 | +`v -cc gcc -prod -cflags "-std=c17 -march=native -mtune=native" .` |
| 14 | + |
| 15 | + |
| 16 | +### Step 1: Create a measurements file |
| 17 | + |
| 18 | +Compile and run `make-samples` to create the sample file. |
| 19 | + |
| 20 | +``` |
| 21 | +cd make-samples |
| 22 | +v -cc gcc -prod -cflags "-std=c17 -march=native -mtune=native" . |
| 23 | +./make-samples 1000000000 > ~/measurements.txt |
| 24 | +``` |
| 25 | + |
| 26 | +NOTE: If you create a billion rows, the file will be about 12GB! |
| 27 | + |
| 28 | +### Step 2: Run (and time) the solution |
| 29 | + |
| 30 | +``` |
| 31 | +cd solution |
| 32 | +v -cc gcc -prod -cflags "-std=c17 -march=native -mtune=native" . |
| 33 | +./solution ~/measurements.txt |
| 34 | +``` |
| 35 | + |
| 36 | +You can time the solution using `v time`: |
| 37 | + |
| 38 | +`v time ./solution ~/measurements.txt` |
| 39 | + |
| 40 | +By default, the solution runs in a single thread. If you want to run |
| 41 | +parallel processing, use the `-n` parameter, for example, to run with |
| 42 | +8 threads: |
| 43 | + |
| 44 | +`./solution -n 8 ~/measurements.txt` |
| 45 | + |
| 46 | +On Linux, to run one thread per core, use |
| 47 | + |
| 48 | +`./solution -n $(nproc) ~/measurements.txt` |
| 49 | + |
| 50 | +### Step 3: Improve upon the solution |
| 51 | + |
| 52 | +Make changes that improve the performance and submit them. |
| 53 | +Let's show off what is possible in V! |
0 commit comments