This repository is a personal challenge to read and process 1 billion rows from a CSV file as quickly as possible using C++. The project leverages modern C++ features and libraries to achieve high performance.
- High-Performance Parsing: Uses memory-mapped file IO for efficient file reading.
- Multi-threading: Utilizes multi-threading to process CSV rows in parallel.
- Custom Hashing: Implements a custom hash function for optimized unordered map usage.
- C++ Compiler: Requires a C++23 compatible compiler.
- CMake: Version 3.28.1 or higher.
- vcpkg: For managing dependencies.
This project uses the following libraries managed via vcpkg:
-
Clone the repository with submodules:
git clone --recurse-submodules https://github.com/yourusername/BillionRowChallenge.git cd BillionRowChallenge -
Create a build directory:
mkdir build cd build -
Configure the project with CMake:
cmake ..
-
Build the project:
cmake --build .
There is no need to bootstrap vcpkg, once the cmake already detects the vcpkg submodule and automatically executes the bootstrap process.
To generate a large CSV dataset, use the provided Python script. This script will create a file named data.csv in the data directory within the project root.
-
Ensure you have Python installed on your system.
-
Run the following command to generate the dataset:
python src/CreateFile.py 1000000000
Replace
1000000000with the desired number of records.
After generating the dataset, you can run the C++ application:
-
Ensure that the generated
data.csvfile is in thedatadirectory. -
Run the application:
./AggregateData
The application will read the CSV, process it, and output the results to output.csv in the data directory.
The application is designed to maximize performance through:
- Memory-mapped File IO: Efficiently handles large files by mapping them into memory.
- Parallel Processing: Splits the workload across multiple threads, leveraging all available CPU cores.
- Optimized Data Structures: Uses
ankerl::unordered_dense::mapwith a custom hash function for fast lookups and inserts.
This project is licensed under the MIT License. See the LICENSE file for details.
For any questions or suggestions, feel free to open an issue or contact me at gabrielandremarquez.matte@gmail.com.