From 5691480d734cc83e7655380b972d53256481622a Mon Sep 17 00:00:00 2001 From: Taco de Wolff Date: Thu, 11 Jan 2024 10:50:17 -0300 Subject: [PATCH] Test new benchmark --- js/benchmark_test.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/js/benchmark_test.go b/js/benchmark_test.go index b04fe76..c905c56 100644 --- a/js/benchmark_test.go +++ b/js/benchmark_test.go @@ -27,6 +27,15 @@ func helperRandString() string { return string(b) } +func helperCaseBytes() []byte { + cs := []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") + b := make([]byte, 100) + for i := range b { + b[i] = cs[rand.Intn(len(cs))] + } + return b +} + func init() { for j := 0; j < len(n); j++ { ms := map[string]bool{} @@ -342,3 +351,27 @@ func BenchmarkMap(b *testing.B) { } } } + +func BenchmarkCompareCase1(b *testing.B) { + v := helperCaseBytes() + b.ResetTimer() + for k := 0; k < b.N; k++ { + for _, c := range v { + if c == 'x' || c == 'X' { + z++ + } + } + } +} + +func BenchmarkCompareCase2(b *testing.B) { + v := helperCaseBytes() + b.ResetTimer() + for k := 0; k < b.N; k++ { + for _, c := range v { + if c|0x20 == 'x' { + z++ + } + } + } +}