fastest c++ serialization?

后端 未结 11 1498
自闭症患者
自闭症患者 2021-02-18 17:57

Good morning all,

I\'m searching for a very fast binary serialization technique for c++. I only need to serialize data contained in objects (no pointers etc.). I\'d like

11条回答
  •  你的背包
    2021-02-18 18:36

    Because I/O is most likely to be the bottleneck a compact format may help. Out of curiosity I tried the following Colfer scheme compiled as colf -s 16 C.

        package data
    
        type item struct {
                off  uint64
                size uint32
        }
    

    ... with a comparable C test:

        clock_t start = clock();
    
        data_item data;
        void* buf = malloc(colfer_size_max);
    
        FILE* fd = fopen( "test.colfer.dat", "wb" );
        for ( long i = 0; i < tests; i++ )
        {
           data.off = i;
           data.size = i & 0xFFFF;
           size_t n = data_item_marshal( &data, buf );
           fwrite( buf, n, 1, fd );
        }
        fclose( fd );
    
        clock_t stop = clock();
    

    The results are quite disappointing on SSD despite the fact that the serial size is 40% smaller in comparison to the raw struct dumps.

        colfer took   0.520 seconds
        plain took    0.320 seconds
    

    Since the generated code is pretty fast it seems unlikely you'll win anything with serialization libraries.

提交回复
热议问题