Skip to content

Instantly share code, notes, and snippets.

@sylr
Created October 26, 2024 11:13
Show Gist options
  • Save sylr/3b409e1936b5bdac4bd0a64846c8643b to your computer and use it in GitHub Desktop.
Save sylr/3b409e1936b5bdac4bd0a64846c8643b to your computer and use it in GitHub Desktop.
package bench
import (
"testing"
"time"
)
func BenchmarkMarshalBinary(b *testing.B) {
bs := make([]byte, 16*4)
for i := 0; i < b.N; i++ {
t := time.Now()
for j := 0; j < 4; j++ {
bs2, err := t.MarshalBinary()
if err != nil {
b.Fatal(err)
}
copy(bs[j*16:], bs2)
}
}
}
func BenchmarkAppendBinary(b *testing.B) {
bs := make([]byte, 16*4)
var err error
for i := 0; i < b.N; i++ {
t := time.Now()
for j := 0; j < 4; j++ {
_, err = t.AppendBinary(bs[j*16 : j*16])
if err != nil {
b.Fatal(err)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment