Created
October 26, 2024 11:13
-
-
Save sylr/3b409e1936b5bdac4bd0a64846c8643b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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