Skip to content

Commit b1d2593

Browse files
authored
examples: add a solution to the "1 Billion Row Challenge" (#23458)
1 parent e0303b2 commit b1d2593

File tree

5 files changed

+705
-0
lines changed

5 files changed

+705
-0
lines changed

cmd/tools/modules/testing/common.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ pub fn new_test_session(_vargs string, will_compile bool) TestSession {
242242
skip_files << 'examples/database/psql/customer.v'
243243
}
244244
$if windows {
245+
skip_files << 'examples/1brc/solution/main.v' // requires mmap
245246
skip_files << 'examples/database/mysql.v'
246247
skip_files << 'examples/database/orm.v'
247248
skip_files << 'examples/smtp/mail.v' // requires OpenSSL

examples/1brc/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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

Comments
 (0)