-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
find_test.go
107 lines (96 loc) · 1.71 KB
/
find_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package gocostmodel
import (
"strconv"
"testing"
)
var (
int5 []int
int100 []int
str5 []string
str100 []string
mint5 = make(map[int]string)
mint100 = make(map[int]string)
mstr5 = make(map[string]string)
mstr100 = make(map[string]string)
mapOut string
)
func init() {
for i := 0; i < 100; i++ {
key := "key " + strconv.Itoa(i)
val := "value for " + strconv.Itoa(i)
if i < 5 {
int5 = append(int5, i)
str5 = append(str5, key)
mint5[i] = key
mstr5[key] = val
}
int100 = append(int100, i)
str100 = append(str100, key)
mint100[i] = key
mstr100[key] = val
}
}
func BenchmarkFindSliceInt5(b *testing.B) {
key := 4
for i := 0; i < b.N; i++ {
for j := 0; j < len(int5); j++ {
if int5[j] == key {
break
}
}
}
}
func BenchmarkFindSliceStr5(b *testing.B) {
key := "key 4"
for i := 0; i < b.N; i++ {
for j := 0; j < len(str5); j++ {
if str5[j] == key {
break
}
}
}
}
func BenchmarkFindSliceInt100(b *testing.B) {
key := 99
for i := 0; i < b.N; i++ {
for j := 0; j < len(int100); j++ {
if int100[j] == key {
break
}
}
}
}
func BenchmarkFindSliceStr100(b *testing.B) {
key := "key 99"
for i := 0; i < b.N; i++ {
for j := 0; j < len(str100); j++ {
if str100[j] == key {
break
}
}
}
}
func BenchmarkFindMapInt5(b *testing.B) {
key := 4
for i := 0; i < b.N; i++ {
mapOut = mint5[key]
}
}
func BenchmarkFindMapStr5(b *testing.B) {
key := "key 4"
for i := 0; i < b.N; i++ {
mapOut = mstr5[key]
}
}
func BenchmarkFindMapInt100(b *testing.B) {
key := 99
for i := 0; i < b.N; i++ {
mapOut = mint100[key]
}
}
func BenchmarkFindMapStr100(b *testing.B) {
key := "key 99"
for i := 0; i < b.N; i++ {
mapOut = mstr100[key]
}
}