https://github.com/mihneats1/fastio
High-Performance Buffered Input for C++
https://github.com/mihneats1/fastio
competitive-coding competitive-programming competitive-programming-contests cpp cpp17 input
Last synced: 11 months ago
JSON representation
High-Performance Buffered Input for C++
- Host: GitHub
- URL: https://github.com/mihneats1/fastio
- Owner: MihneaTs1
- Created: 2025-06-09T06:05:56.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-06-09T06:16:33.000Z (12 months ago)
- Last Synced: 2025-06-09T07:23:16.325Z (12 months ago)
- Topics: competitive-coding, competitive-programming, competitive-programming-contests, cpp, cpp17, input
- Language: C++
- Homepage:
- Size: 5.86 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FastIO: High-Performance Buffered Input for C++
FastIO is a modern, header-only C++ library for extremely fast, buffered input from files or standard input. It is designed for competitive programming, data processing, and any scenario where input speed is critical.
## Features
- **Blazing fast**: Uses a large buffer and minimal parsing overhead for maximum throughput.
- **Type-safe**: Supports reading `int`, `long long`, `double`, `bool`, `std::string`, `char`, and C-style strings (`char*`) out of the box.
- **Flexible**: Works with any `FILE*` stream (default: `stdin`).
- **Modern C++**: Written in C++17, using best practices and zero dependencies beyond the standard library.
- **Simple API**: One header, one class, one function to read any supported type.
## Usage
Include the header and use the `FastIO` class:
```cpp
#include "fastio.hpp"
FastIO io;
int x = io.next();
double y = io.next();
bool b = io.next();
std::string s = io.next();
char c = io.next();
char buf[32];
io.next(buf, sizeof(buf)); // Reads a word into buf (C-style string)
```
You can also use a custom file pointer:
```cpp
FILE* f = fopen("input.txt", "rb");
FastIO io(f);
// ...
fclose(f);
```
## Benchmark
A benchmark is provided in `benchmark.cpp` to compare FastIO's performance for various types:
- Generates large datasets for `int`, `long long`, `double`, `bool`, `std::string`, `char`, and C-style strings (`char*`).
- Measures throughput (MB/s) and total time to read all values.
### Build and Run with Makefile
A `Makefile` is provided for convenience:
```sh
make # Builds the benchmark executable
make run # Builds and runs the benchmark
make clean # Removes the executable and generated data files
```
### Manual Build
You can also build manually:
```sh
g++ -Ofast -std=c++17 benchmark.cpp -o benchmark
./benchmark
```
## License
Copyright (c) Mihnea-Teodor Stoica 2025
This project is licensed under the MIT License. See the source file headers for details.