Created
August 6, 2021 10:42
-
-
Save Seb-C/d20fb7bfa4fe6cc3e4d2b877828c080c to your computer and use it in GitHub Desktop.
This file contains hidden or 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 test | |
| import ( | |
| "bytes" | |
| "encoding/binary" | |
| "testing" | |
| ) | |
| type TestDataStruct struct { | |
| Int int64 | |
| Float float64 | |
| String string | |
| } | |
| func BenchmarkEndianness(b *testing.B) { | |
| buf := &bytes.Buffer{} | |
| b.Run("little endian", func(b *testing.B) { | |
| for i := 0; i < b.N; i++ { | |
| if err := binary.Write(buf, binary.LittleEndian, TestDataStruct{42, 3.14, "test"}); err != nil { | |
| b.Fatalf("Unexpected error: '%+v'", err) | |
| } | |
| } | |
| }) | |
| b.Run("big endian", func(b *testing.B) { | |
| for i := 0; i < b.N; i++ { | |
| if err := binary.Write(buf, binary.BigEndian, TestDataStruct{42, 3.14, "test"}); err != nil { | |
| b.Fatalf("Unexpected error: '%+v'", err) | |
| } | |
| } | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment