Skip to content

Commit

Permalink
bench: hex.EncodeToString with array being sliced
Browse files Browse the repository at this point in the history
  • Loading branch information
catenacyber committed Nov 6, 2023
1 parent 9cd4cff commit 838fa0d
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions analyzer/replacements_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,24 @@ func BenchmarkHexEncoding(b *testing.B) {
})
}

func BenchmarkHexArrayEncoding(b *testing.B) {
b.Run("fmt.Sprintf", func(b *testing.B) {
for n := 0; n < b.N; n++ {
val := [3]byte{'a', 'b', 'c'}
_ = fmt.Sprintf("%x", val)
}
b.ReportAllocs()
})

b.Run("hex.EncodeToString", func(b *testing.B) {
for n := 0; n < b.N; n++ {
val := [3]byte{'a', 'b', 'c'}
_ = hex.EncodeToString(val[:])
}
b.ReportAllocs()
})
}

func BenchmarkIntFormatting(b *testing.B) {
b.Run("fmt.Sprint", func(b *testing.B) {
for n := 0; n < b.N; n++ {
Expand Down

0 comments on commit 838fa0d

Please sign in to comment.