-
Notifications
You must be signed in to change notification settings - Fork 4
/
string_compare_test.go
47 lines (40 loc) · 980 Bytes
/
string_compare_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"strings"
"testing"
)
var (
_emptyString = ""
_notEmptyString = strings.Repeat("test", 1000)
_boolResult bool
)
func BenchmarkCompareStringEmpty(b *testing.B) {
for i := 0; i < b.N; i++ {
_boolResult = (_emptyString == "")
_boolResult = (_notEmptyString == "")
}
}
func BenchmarkCompareStringLen0(b *testing.B) {
for i := 0; i < b.N; i++ {
_boolResult = (len(_emptyString) == 0)
_boolResult = (len(_notEmptyString) == 0)
}
}
func BenchmarkCompareStringLenGreater0(b *testing.B) {
for i := 0; i < b.N; i++ {
_boolResult = (len(_emptyString) > 0)
_boolResult = (len(_notEmptyString) > 0)
}
}
func BenchmarkCompareStringLenNot0(b *testing.B) {
for i := 0; i < b.N; i++ {
_boolResult = (len(_emptyString) != 0)
_boolResult = (len(_notEmptyString) != 0)
}
}
func BenchmarkCompareStringNotEmpty(b *testing.B) {
for i := 0; i < b.N; i++ {
_boolResult = (_emptyString != "")
_boolResult = (_notEmptyString != "")
}
}