Skip to content

Commit

Permalink
examples: add a solution to the "1 Billion Row Challenge" (#23458)
Browse files Browse the repository at this point in the history
  • Loading branch information
syrmel authored Jan 15, 2025
1 parent e0303b2 commit b1d2593
Show file tree
Hide file tree
Showing 5 changed files with 705 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/tools/modules/testing/common.v
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ pub fn new_test_session(_vargs string, will_compile bool) TestSession {
skip_files << 'examples/database/psql/customer.v'
}
$if windows {
skip_files << 'examples/1brc/solution/main.v' // requires mmap
skip_files << 'examples/database/mysql.v'
skip_files << 'examples/database/orm.v'
skip_files << 'examples/smtp/mail.v' // requires OpenSSL
Expand Down
53 changes: 53 additions & 0 deletions examples/1brc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# 1 Billion Row Challenge (1BRC)

A solution to the [1 Billion Row Challenge](https://www.morling.dev/blog/one-billion-row-challenge/),
written in [the V programming language](https://vlang.io/).

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!
Loading

0 comments on commit b1d2593

Please sign in to comment.