Giter Club home page Giter Club logo

1br-challenge's Introduction

Single Threaded One Billion Rows Challenge

This is a solution to the one billion rows challenge using a single thread in C++. Not optimized at all, but still faster than most multi-threaded solutions.

Results

Hardware Time (seconds)
Apple M2 0.55

Reason to Not Use Multi-threading

This is only a 12 Gb file, and the calculation is extremely simple (two comparisons and one addition each iteration). Thus, the bottleneck is going to be the IO operation of reading the file. In fact, using multi-threading will make it slower due to the added overhead of context switching.

Methods

  • From my experience, reading binary files (both signle and multi-threaded) using memory mapped files is the best, especially when the file is large.
    • I used my encryption memory mapping class to read the file.
  • The cost of a IO heavy operation like reading a file is mostly from actually accessing the memory mapped pointer to the file. Thus, it is best to minimize the number of times the pointer is accessed. In this case, each character only need to be accessed once from the memory mapped pointer.
  • The map that keeps track of the statistics of each city can just use std::string since it didn't give me much of a performance improvement when I used custom comparator and equality checker with char*.
  • The map or specifically std::unordered_map should be used since the challenge said there will be at most 10,000 cities. Using std::unordered_map allows us to call std::unordered_map::reserve(int) to make inserts O(1) instead of O(log n).

1br-challenge's People

Contributors

2042third 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.