Skip to content

Commit

Permalink
Test new benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Jan 11, 2024
1 parent cd8aa3e commit 5691480
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions js/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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++
}
}
}
}

0 comments on commit 5691480

Please sign in to comment.