Giter Club home page Giter Club logo

fast_io's Introduction

fast_io

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.

Compiler Support

  • VS 16.3
  • Clang 10.0
  • GCC 10

Platform Support

  • Windows
  • Linux
  • MacOS
  • Android

Design Goal

Fast. As close to system call as possible.

  • Locale support optional
  • Zero copy IO

Safe

  • No easily misused stuff like std::endl
  • No internal iomanip states (since it creates security issues)
  • Providing RAII for FILE*&POSIX file id

Easy to use

  • Unicode/UTF-8 support
  • Compatible with C stdio and C++ iostream
  • Binary serialization for trivially copyable types and C++ standard library containers
  • All fast_io devices can be natively put in C++ containers. std::vector<fast_io::obuf> is valid
  • Support C style io format (fprint). Basic/Lua/Python/etc format (print, scan).

Customizability

  • Exception Safe & Exception neutral
  • Native Handle Interface
  • Extremely easy to support custom devices
  • std::mutex mutex stream
  • Compilation time open mode parse. Supports C style open mode and C++ style open mode.
  • No traits_type and EOF
  • Dynamic Type Support
  • Pipe line support
  • Cryptography (Under construction) to replace openssl
  • debugging IO

Post C++20 Plan

  1. Module support
  2. Coroutine support for async IO
  3. Improve and refactor code once Zero-overhead deterministic exceptions are added to the standard
  4. Network handle support with coroutine. (NOT ASIO library)
  5. Partial freestanding mode

Possible Improvements

  1. Compression/Decompression
  2. Interfaces for cloud computing algorithms like MapReduce

I'm aiming for this to be in the C++ standard library in the future :)

Getting Started

Please see examples in the examples folder.

compile option:

g++ -o example example.cc -O2 -std=c++2a -fconcepts

Documentation

./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.

Benchmarks

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

Windows:

Output:

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:

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

Updated benchmark with trunk gcc

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

fast_io's People

Contributors

zyddnys avatar stijnherfst avatar ilyapopov avatar

Watchers

James Cloos avatar  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.