- C++ 82.9%
- Meson 17.1%
|
|
||
|---|---|---|
| src | ||
| test | ||
| .clangd | ||
| .gitignore | ||
| LICENSE | ||
| meson.build | ||
| README.md | ||
CSV Parser
C++ module for single-threaded CSV parsing.
Usage
A delimited file can be loaded into a csv::dataframe object by calling csv::parse(pathname, delimiter, buffersize). Alternatively, one can call csv::parse(pathname), which will default to delimiter= ',' and buffersize = 1 MB.
Example
import csv;
import std;
int main() {
std::string filepath = "/path/to/file";
char delimiter = ',';
std::size_t buffersize = 1024*1024;
auto parsed_data = csv::parse(filepath, delimiter, buffersize)
if (!parsed_data.has_value()) {
std::println("{}", parsed_data.error().message);
return -1;
}
auto df = std::move(parsed_data.value());
auto data_view = std::mdspan(df.data.data(), df.rows, df.columns);
}
Building
A build system is provided as a way to run tests and as an example on how to use the module. The project is setup to be built with Meson and requires C++23 support.
The project can be built with
-
Linux
meson setup build ninja -C build ./build/csv, which will default to the GCC compiler if available (GCC 16+ required). Alternatively, an LLVM (LLVM 22+ required) build path is provided, available with
CXX=clang++ meson setup build. -
Windows
meson setup build --vsenv meson compile -C build ./build/csv
Release builds are made available through Meson, with the command line argument --buildtype=release during the setup step: meson setup build --buildtype=release
Performance
These are the average duration of a csv::parse() call for each file.
- Setup:
- Linux 7.0
- Clang 22.1.6 (-O3 optimization level)
- Ryzen 4800H
- Results
- Electric Vehicle Population Data
- ~110 ms
- Motor Vehicle Collisions - Crashes
- ~1240 ms
- U.S. Chronic Disease Indicators
- ~210 ms
- Electric Vehicle Population Data