3 ms·
I just tried the switch statement ``` func BenchmarkSwitch(b *testing.B) { for i := 0; i < b.N; i++ { for i := 0; i < len(randomBytes); i++ { loop: for
by boris-smidt 2y ago
I just tried the switch statement
```
func BenchmarkSwitch(b *testing.B) {
for i := 0; i < b.N; i++ {
for i := 0; i < len(randomBytes); i++ {
loop:
for i, x := range randomBytes[i:] {
switch x {
case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
result = i != 0
break loop
case 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'y', 'z':
result = i != 0
break loop
case 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'Y', 'Z':
result = i != 0
break loop
}
}
}
}
}
```
It isn't any faster than the || compare, so i suspect the go compiler doesn't really treat it like a special case.