Coder Social home page Coder Social logo

lk4d4 / go_serialization_benchmarks Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alecthomas/go_serialization_benchmarks

0.0 2.0 0.0 112 KB

Benchmarks of Go serialization methods

Go 90.14% Makefile 5.17% Shell 1.97% Protocol Buffer 1.92% Cap'n Proto 0.81%

go_serialization_benchmarks's Introduction

Benchmarks of Go serialization methods

This is a test suite for benchmarking various Go serialization methods.

Tested serialization methods

Running the benchmarks

go get -u -t
go test -bench='.*' ./

Shameless plug: I use pawk to format the table:

go test -bench='.*' ./ | pawk -F'\t' '"%-40s %10s %10s %s %s" % f'

Recommendation

If performance, correctness and interoperability are the most important factors, gogoprotobuf is currently the best choice. It does require a pre-processing step (eg. via Go 1.4's "go generate" command).

But as always, make your own choice based on your requirements.

Data

The data being serialized is the following structure with randomly generated values:

type A struct {
    Name     string
    BirthDay time.Time
    Phone    string
    Siblings int
    Spouse   bool
    Money    float64
}

Results

Results with Go 1.6 on a 3.1 GHz Intel Core i7 (MacBook Pro (Retina, 13-inch, Early 2015)):

benchmark                                   iter           time/iter      bytes alloc               allocs
---------                                   ----           ---------      -----------               ------
BenchmarkMsgpMarshal-4                      5000000        274 ns/op      128 B/op        1 allocs/op
BenchmarkMsgpUnmarshal-4                    3000000        493 ns/op      112 B/op        3 allocs/op
BenchmarkVmihailencoMsgpackMarshal-4        1000000       1681 ns/op      352 B/op        5 allocs/op
BenchmarkVmihailencoMsgpackUnmarshal-4      1000000       2120 ns/op      352 B/op       13 allocs/op
BenchmarkJsonMarshal-4                       500000       3498 ns/op     1232 B/op       10 allocs/op
BenchmarkJsonUnmarshal-4                     500000       3596 ns/op      415 B/op        7 allocs/op
BenchmarkEasyJsonMarshal-4                  1000000       1715 ns/op      784 B/op        5 allocs/op
BenchmarkEasyJsonUnmarshal-4                1000000       1585 ns/op      160 B/op        4 allocs/op
BenchmarkBsonMarshal-4                      1000000       1816 ns/op      392 B/op       10 allocs/op
BenchmarkBsonUnmarshal-4                    1000000       2352 ns/op      248 B/op       21 allocs/op
BenchmarkGobMarshal-4                       1000000       1174 ns/op       48 B/op        2 allocs/op
BenchmarkGobUnmarshal-4                     1000000       1147 ns/op      112 B/op        3 allocs/op
BenchmarkXdrMarshal-4                       1000000       2231 ns/op      455 B/op       20 allocs/op
BenchmarkXdrUnmarshal-4                     1000000       1740 ns/op      239 B/op       11 allocs/op
BenchmarkUgorjiCodecMsgpackMarshal-4         500000       3103 ns/op     2753 B/op        8 allocs/op
BenchmarkUgorjiCodecMsgpackUnmarshal-4       500000       3341 ns/op     3008 B/op        6 allocs/op
BenchmarkUgorjiCodecBincMarshal-4            500000       3156 ns/op     2785 B/op        8 allocs/op
BenchmarkUgorjiCodecBincUnmarshal-4          500000       3601 ns/op     3168 B/op        9 allocs/op
BenchmarkSerealMarshal-4                     300000       4171 ns/op      912 B/op       21 allocs/op
BenchmarkSerealUnmarshal-4                   500000       3738 ns/op     1008 B/op       34 allocs/op
BenchmarkBinaryMarshal-4                    1000000       1738 ns/op      256 B/op       16 allocs/op
BenchmarkBinaryUnmarshal-4                  1000000       1867 ns/op      336 B/op       22 allocs/op
BenchmarkFlatbuffersMarshal-4               5000000        389 ns/op        0 B/op        0 allocs/op
BenchmarkFlatBuffersUnmarshal-4             5000000        345 ns/op      112 B/op        3 allocs/op
BenchmarkCapNProtoMarshal-4                 3000000        553 ns/op       56 B/op        2 allocs/op
BenchmarkCapNProtoUnmarshal-4               3000000        514 ns/op      216 B/op        6 allocs/op
BenchmarkCapNProto2Marshal-4                1000000       1358 ns/op      436 B/op       12 allocs/op
BenchmarkCapNProto2Unmarshal-4              1000000       1165 ns/op      464 B/op       12 allocs/op
BenchmarkHproseMarshal-4                    1000000       1183 ns/op      478 B/op        8 allocs/op
BenchmarkHproseUnmarshal-4                  1000000       1433 ns/op      320 B/op       10 allocs/op
BenchmarkProtobufMarshal-4                  1000000       1264 ns/op      200 B/op        7 allocs/op
BenchmarkProtobufUnmarshal-4                2000000        974 ns/op      192 B/op       10 allocs/op
BenchmarkGoprotobufMarshal-4                2000000        743 ns/op      312 B/op        4 allocs/op
BenchmarkGoprotobufUnmarshal-4              1000000       1006 ns/op      432 B/op        9 allocs/op
BenchmarkGogoprotobufMarshal-4             10000000        212 ns/op       64 B/op        1 allocs/op
BenchmarkGogoprotobufUnmarshal-4            5000000        296 ns/op       96 B/op        3 allocs/op
BenchmarkGencodeMarshal-4                  10000000        216 ns/op       80 B/op        2 allocs/op
BenchmarkGencodeUnmarshal-4                 5000000        257 ns/op      112 B/op        3 allocs/op

Issues

The benchmarks can also be run with validation enabled.

VALIDATE=1 go test -bench='.*' ./

Unfortunately, several of the serializers exhibit issues:

  1. (minor) BSON drops sub-microsecond precision from time.Time.
  2. (minor) Ugorji Binc Codec drops the timezone name (eg. "EST" -> "-0500") from time.Time.
--- FAIL: BenchmarkBsonUnmarshal-8
    serialization_benchmarks_test.go:115: unmarshaled object differed:
        &{20b999e3621bd773 2016-01-19 14:05:02.469416459 -0800 PST f017c8e9de 4 true 0.20887343719329818}
        &{20b999e3621bd773 2016-01-19 14:05:02.469 -0800 PST f017c8e9de 4 true 0.20887343719329818}
--- FAIL: BenchmarkUgorjiCodecBincUnmarshal-8
    serialization_benchmarks_test.go:115: unmarshaled object differed:
        &{20a1757ced6b488e 2016-01-19 14:05:15.69474534 -0800 PST 71f3bf4233 0 false 0.8712180830484527}
        &{20a1757ced6b488e 2016-01-19 14:05:15.69474534 -0800 -0800 71f3bf4233 0 false 0.8712180830484527}

All other fields are correct however.

Additionally, while not a correctness issue, FlatBuffers, ProtoBuffers and Cap'N'Proto do not support time types directly. In the benchmarks an int64 value is used to hold a UnixNano timestamp.

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.