Global Feed Post Login
Replying to Avatar ᴛʜᴇ ᴅᴇᴀᴛʜ ᴏꜰ ᴍʟᴇᴋᴜ

cpu: AMD Ryzen 5 PRO 4650G with Radeon Graphics

BenchmarkBinaryEncoding

BenchmarkBinaryEncoding/gob.Encode

BenchmarkBinaryEncoding/gob.Encode-12 6886 151743 ns/op

BenchmarkBinaryEncoding/binary.Marshal

BenchmarkBinaryEncoding/binary.Marshal-12 5544 204894 ns/op

BenchmarkBinaryEncoding/binary.MarshalBinary

BenchmarkBinaryEncoding/binary.MarshalBinary-12 5832 203333 ns/op

this is how the code should have looked to be fair

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()

}

}

})

and yes, i was right, it's almost 25% faster than your thing

Avatar
ᴛʜᴇ ᴅᴇᴀᴛʜ ᴏꜰ ᴍʟᴇᴋᴜ 1y ago

also, there is a gob register function, which registers a type for encoding, i'm surprised that you didn't use it, it probably makes it even faster

Reply to this note

Please Login to reply.

Discussion

No replies yet.