Monday, May 25, 2020

I/O library 6x faster than fmt, 10x faster than stdio.h and iostream


This is a new header-only (module only in the future) Experimental library to replace iostream and cstdio based on C++ 2a feature concepts. Currently, the only compiler which supports Concepts TS is GCC. Supports VC preview as well. It can compile on clang concepts experimental. I have tested all the compilers.

It can even work on android !!

Documents

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

Design goal.

  1. Custom Devices
  2. Exception Safe & Exception neutral
  3. As fast as possible. As close to system call as possible.
  4. Zero Overhead.
  5. As safe as possible.
  6. Binary serialization for trivially copyable types and C++ standard library containers. Serialization methods like JSON are slow and tedious for machines. read/write
  7. std::mutex mutex stream
  8. Unicode/UTF-8 support
  9. Compatible with C stdio/ C++ iostream
  10. Native Handle Interface
  11. support C style io format (fprint). Basic/Lua/Python/etc format (print, scan). NO LONGER SUPPORTS C++ style io format (<<,>>) since we have varadics templates now. Using operator overloading incurs more overhead including compilation and runtime. I could not do optimization like avoiding multiple locking.
  12. Compilation time open mode parse. Supports C style open mode and C++ style open mode.
  13. No internal iomanip states (since it creates security issues)
  14. Extremely easy to support custom devices
  15. No easily misused stuff like std::endl
  16. No integrated locale
  17. No traits_type and EOF
  18. All fast_io devices can be natively put in C++ containers. std::vector<fast_io::obuf> is valid
  19. Providing RAII for FILE*&POSIX file id
  20. Dynamic Type Support
  21. Pipe line support
  22. Zero copy IO
  23. Cryptography (Under construction) to replace openssl
  24. debugging IO
  25. GUI debugger (calling win32 apis MessageBox for those who are doing none console programming)

Future Plan After C++ 20

  1. Module support
  2. Coroutine support for async IO
  3. if this proposal would be released. Probably remove more stuffs here Zero-overhead deterministic exceptions: Throwing values http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0709r0.pdf
  4. Network handle support with coroutine. (NOT ASIO library) NETWORK SUPPORT IS BECOMING MORE AND MORE IMPORTANT IN MODERN WORLD
  5. Partial Freestanding mode

Possible Stuff in the future

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

I want this to be in the C++ standard library in the future. :)

How to use this library?

Please see examples in the examples folder.

compile option:

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

Compiler recommendation under windows:

https://gcc-mcf.lhmouse.com/

Benchmark

output 10000000 size_t to file

root@XXXXXX:/mnt/d/hg/fast_io/tests# ./i 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

root@XXXXXX:/mnt/d/hg/fast_io/tests# ./j std::FILE*: 1.04546250s std::ifstream: 0.47838780s ibuf: 0.08077780s 

Windows:

Output:

g++ -o output_10M_size_t output_10M_size_t.cc -O2 -std=c++2a -fconcepts Process started (PID=1580) >>> <<< Process finished (PID=1580). (Exit code 0) output_10M_size_t Process started (PID=1208) >>> 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:

g++ -o input_10M_size_t input_10M_size_t.cc -O2 -std=c++2a -fconcepts Process started (PID=11856) >>> <<< Process finished (PID=11856). (Exit code 0) input_10M_size_t Process started (PID=21088) >>> std::FILE*: 5.53888200s std::ifstream: 1.27124600s ibuf: 0.07400200s dynamic standard input stream ibuf: 0.08899900s ibuf_dynamic inative_file: 0.07600900s 

visual studio preview 2019 https://visualstudio.microsoft.com/vs/preview/

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.

 cqwrteur@DESKTOP-7H7UHQ9:~/fast_io/examples/build$ g++ --version g++ (cqwrteur) 10.0.0 20191031 (experimental) Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. cqwrteur@DESKTOP-7H7UHQ9:~/fast_io/examples/build$ ./output_10M_size_t 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 


from Hacker News https://ift.tt/2pGqjlE

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.