you wrote the test wrong, gob is actually 25% faster

Reply to this note

Please Login to reply.

Discussion

Please send me your benchmark code.

i put it in another reply

all i did was move the create codec step to outside the loop

b.Run("gob.Encode", func(b *testing.B) {

var buf bytes.Buffer

enc := gob.NewEncoder(&buf)

for i := 0; i < b.N; i++ {

for _, evt := range events {

enc.Encode(evt)

// _ = buf.Bytes()

}

}

})

also as you can see to not actually access the buffer using buf.Bytes()

neither of these steps really reflect any distinctive part of the process, but i doubt that step takes more than a dozen nanoseconds

Don't you have to .Reset() the buffer or something like that? Otherwise you'll be appending to the same buffer over and over and it will get huge and reallocate all the time.

well, make the change, it's way faster, but yes, probably it should be doing buf.Reset()

i'm probably gonna have to write a better bytes.Buffer now after seeing this shit

also, maybe bufio is the droids we are looking for here