Giter Club home page Giter Club logo

cpp_serializers_benchmark's Introduction

CPP serializers benchmark

tested libraries

GCC 8.3.0 (Ubuntu 18.04 x64)

library test case bin size data size ser time des time
bitsery general 74704B 6913B 1252ms 1170ms
bitsery brief syntax1 74376B 6913B 1044ms 1022ms
bitsery compatibility2 78768B 7113B 1295ms 1213ms
bitsery compression3 74664B 4213B 1445ms 1325ms
bitsery fixed buffer4 45704B 6913B 1061ms 1203ms
bitsery stream5 55384B 6913B 1644ms 4350ms
bitsery unsafe read6 70808B 6913B 1276ms 1091ms
boost general 270264B 11037B 9952ms 8767ms
cereal general 81232B 10413B 6497ms 5470ms
flatbuffers general 65760B 14924B 6762ms 2173ms
handwritten general7 39272B 10413B 1042ms 896ms
handwritten unsafe8 39280B 10413B 1095ms 819ms
iostream general9 49136B 8413B 7546ms 8915ms
protobuf general 1920384B 10018B 12202ms 15096ms
protobuf arena10 1920568B 10018B 6836ms 9919ms
yas general11 59576B 10463B 1352ms 1109ms
yas compression12 72840B 7315B 1673ms 1598ms
yas stream13 50992B 10463B 7377ms 7566ms
zpp general 45360B 8413B 1127ms 1102ms

Clang 8.0.1 (Ubuntu 18.04 x64)

library test case bin size data size ser time des time
bitsery general 45776B 6913B 1857ms 1322ms
bitsery brief syntax1 51320B 6913B 1997ms 1382ms
bitsery compatibility2 50608B 7113B 1900ms 1394ms
bitsery compression3 50888B 4213B 3215ms 2976ms
bitsery fixed buffer4 45024B 6913B 1029ms 1404ms
bitsery stream5 46536B 6913B 1739ms 4406ms
bitsery unsafe read6 45664B 6913B 1845ms 927ms
boost general 235752B 11037B 12056ms 10384ms
cereal general 52904B 10413B 7328ms 6130ms
flatbuffers general 57912B 14924B 8107ms 2296ms
handwritten general7 38632B 10413B 1011ms 796ms
handwritten unsafe8 38632B 10413B 984ms 749ms
iostream general9 40312B 8413B 7756ms 8914ms
protobuf general 1762016B 10018B 11198ms 15622ms
protobuf arena10 1762224B 10018B 6040ms 10418ms
yas general11 46728B 10463B 1356ms 1027ms
yas compression12 51384B 7315B 1926ms 1589ms
yas stream13 46112B 10463B 7254ms 7728ms
zpp general 47832B 8413B 1297ms 1137ms

Additional tests information

  1. forward/backward compatibility enabled for Monster
  2. all components of Vec3 is compressed in [-1.0, 1.0] range with precision 0.01
  3. use non-resizable buffer uint8_t[150000] for serialization
  4. deserialization using brief_syntax syntax, similar to cereal
  5. use stream input/output adapter, underlying type is std::stringstream
  6. on deserialization do not check for buffer end
  7. check buffer size on reading, but writing buffer is preallocated std::array<uint8_t, 1000000>
  8. doesn't check for buffer size when reading, buffer: std::array<uint8_t, 1000000>
  9. use std::stringstream's internal std::string
  10. use arena allocator
  11. use yas::mem_<io>stream as buffer
  12. with yas::no_header and yas::compacted
  13. using std::stringstream

NOTE: tests for protobuf and flatbuffers is not 100% fair, because huge amount of CPU cycles goes to converting from generated types, to our defined types.

Why another cpp serializers benchmark

I'm aware that cpp-serializers project already exists, but it's testing set is way too simple and you cannot compile each project to separate executable.

This project contains more realisting data that needs to be serialized.

    enum Color : uint8_t {
        Red,
        Green,
        Blue
    };

    struct Vec3 {
        float x;
        float y;
        float z;
    };

    struct Weapon {
        std::string name;
        int16_t damage;
    };

    struct Monster {
        Vec3 pos;
        int16_t mana;
        int16_t hp;
        std::string name;
        std::vector<uint8_t> inventory;
        Color color;
        std::vector<Weapon> weapons;
        Weapon equipped;
        std::vector<Vec3> path;
    };

All data is random generated, although seed is hard-coded to get predictable results when running same test multiple times.

All projects implement same interface for serialization and deserialization.

struct Buf {
    const uint8_t* ptr;
    size_t bytesCount;
};

class ISerializerTest {
public:
    virtual Buf serialize(const std::vector<MyTypes::Monster>& data) = 0;
    virtual void deserialize(Buf buf, std::vector<MyTypes::Monster>& res) = 0;
    virtual ~ISerializerTest() = default;
};

Testing routine consist of few steps:

  • data generation step, in which monsters are generated (default 50 monsters)
  • warmup step, in which serialization and deserialization is run 5 times, to warmup cpu cache and check if deserialized data equals to original data.
  • measurement step, runs serialization and deserialization multiple times (default 300000 samples), deserialization happens on same object, to avoid costly allocate operations for new object construction each time.

Building & testing

  1. Build project
    mkdir build && cd build
    cmake ..
    make
  2. Run tests with ctest -VV OR
  3. Generate testing results (requires nodejs)
    cd ../tools/
    npm install
    npm start

cpp_serializers_benchmark's People

Contributors

eyalz800 avatar fraillt avatar ned14 avatar nixman avatar

Watchers

 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.