expnkx / fast_io
- четверг, 28 мая 2020 г. в 00:22:18
C++
fast_io is a C++ io exception-safe RAII library based on C++ 20 Concepts. It is at least 10 times faster than cstdio than iostream.
fast_io is a new C++20 library for extremely fast input/output and aims to replace iostream and cstdio. It is header-only (module only in the future) for easy inclusion in your project. It requires a capable C++20 compiler supporting concepts.
I'm aiming for this to be in the C++ standard library in the future :)
Please see examples in the examples folder.
compile option:
g++ -o example example.cc -O2 -std=c++2a -fconcepts
./doxygen/html/index.html
Since C++ 20 has not been released. No standard supporting libraries for concepts, which means a lot of Concepts Definitions are ugly. It will be changed after C++ 20 is officially published.
output 10000000 size_t to file
/fast_io/tests# ./i
Method | Time |
---|---|
std::FILE*: | 1.03459230s |
std::ofstream: | 0.59182820s |
std::ofstream with tricks: | 0.39233580s |
obuf: | 0.13328110s |
obuf_mutex: | 0.13685030s |
input 10000000 size_t from file
fast_io/tests ./j
Method | Time |
---|---|
std::FILE*: | 1.04546250s |
std::ifstream: | 0.47838780s |
ibuf: | 0.08077780s |
output_10M_size_t.cc -O2 -std=c++2a -fconcepts
Method | Time |
---|---|
std::FILE*: | 2.26901100s |
std::ofstream: | 1.03628600s |
std::ofstream with tricks: | 0.84219500s |
obuf: | 0.13401100s |
dynamic obuf: | 0.13586300s |
iobuf_dynamic native_file: | 0.13000100s |
obuf_mutex: | 0.15303500s |
input_10M_size_t.cc -O2 -std=c++2a -fconcepts
Method | Time |
---|---|
std::FILE*: | 5.53888200s |
std::ifstream: | 1.27124600s |
ibuf: | 0.07400200s |
dynamic standard input stream ibuf: | 0.08899900s |
ibuf_dynamic inative_file: | 0.07600900s |
I did some optimizations to my fast_io library. Now there is NO reason to use charconv any more. It is insecure and the APIs are terrible. I hope isocpp would deprecate charconv in the future.
fast_io/examples/
Method | Time |
---|---|
std::FILE*: | 0.56558740s |
std::ofstream: | 0.57254780s |
std::ofstream with tricks: | 0.37952570s |
std::to_chars + ofstream rdbuf tricks: | 0.16530360s |
std::to_chars + obuf: | 0.12705310s |
obuf: | 0.07508470s |
obuf text: | 0.13640670s |
steam_view for ofstream: | 0.35196200s |
steambuf_view for ofstream: | 0.15705550s |
obuf ucs_view: | 0.15152370s |
obuf_mutex: | 0.08375820s |
fsync: | 0.17738210s |
speck128/128: | 0.26626790s |