Git Product home page Git Product logo

1brc's Introduction

The One Billion Row Challenge

Overview

I tried out the Billion Row Challenge using Golang. This is a challenge to read and process a one billion line text file efficiently. It's a fun problem for practicing performance benchmarking and optimization.

I've included several iterations on the challenge in the /solutions directory. I attempted a few different optimizations before settling on 4_customscan. The hallmarks of this solution are:

  1. Divide reading the file between multiple goroutines.
  2. Optimize the file reading such that each byte is only read once.

I was able to achieve 2.97s for 1 billion rows on a 2021 M1 Macbook Pro. For context, reading this file without performing any processing takes 1.92s.

Benchmarks

go test -run=xxx -bench=Benchmark/data -benchmem -benchtime=10s
goos: darwin
goarch: arm64
pkg: 1brc
Benchmark/data/10m/baseline-10     596  19990858 ns/op    38 B/op        1 allocs/op
Benchmark/data/10m/solution/4-10   312  37987268 ns/op    21755002 B/op  16962 allocs/op
Benchmark/data/100m/baseline-10    60   201109167 ns/op   310 B/op       1 allocs/op
Benchmark/data/100m/solution/4-10  36   339840758 ns/op   21755636 B/op  16966 allocs/op
Benchmark/data/1b/baseline-10      6    1920414868 ns/op  1634 B/op      2 allocs/op
Benchmark/data/1b/solution/4-10    4    2968820927 ns/op  21753862 B/op  16958 allocs/op
PASS
ok  	1brc	92.076s

1brc's People

Contributors

armsnyder avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.