Debian Codegraph @

benchmark_test.go

raw symbols SCIP
1 package asciisetscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/
2
3 import (
4 "testingscip-go gomod github.com/golang/go/src go1.11 testing/"
5 "unicode/utf8scip-go gomod github.com/golang/go/src go1.11 `unicode/utf8`/"
6 )
7
8 // prevent compiler from erroneously optimising benchmark computations
9 var globalExistsscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/globalExists. bool
10 var globalSizescip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/globalSize. int
11 var globalValscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/globalVal. byte
12
13 // Number of sets
14 const Nscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/N. int = 10
15
16 // setupASCIISets returns an ASCIISet slice of size n where
17 // each ASCIISet is empty
18 //
19 // if populate is true, fill each set with every 2nd ASCII character
20 func setupASCIISetsscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/setupASCIISets().(n int, populate bool) []ASCIISetscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/ASCIISet# {
21 sets := []ASCIISetscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/ASCIISet#{}
22 for i := 0; i < n; i++ {
23 var as ASCIISetscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/ASCIISet#
24 if populate {
25 for c := 0; c < utf8scip-go gomod github.com/golang/go/src go1.11 `unicode/utf8`/.RuneSelfscip-go gomod github.com/golang/go/src go1.11 `unicode/utf8`/RuneSelf.; c += 2 {
26 // add every 2nd ASCII character
27 as.Addscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/ASCIISet#Add().(byte(c))
28 }
29 }
30 sets = append(sets, as)
31 }
32 return sets
33 }
34
35 // setupMapSets returns a map[byte]struct{} slice of size n where
36 // each map[byte]struct{} is empty
37 //
38 // if populate is true, fill each set with every 2nd ASCII character
39 func setupMapSetsscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/setupMapSets().(n int, populate bool) []map[byte]struct{} {
40 sets := []map[byte]struct{}{}
41 for i := 0; i < n; i++ {
42 as := make(map[byte]struct{})
43 if populate {
44 for c := 0; c < utf8scip-go gomod github.com/golang/go/src go1.11 `unicode/utf8`/.RuneSelfscip-go gomod github.com/golang/go/src go1.11 `unicode/utf8`/RuneSelf.; c += 2 {
45 // add every 2nd ASCII character
46 as[byte(c)] = struct{}{}
47 }
48 }
49 sets = append(sets, as)
50 }
51 return sets
52 }
53
54 func BenchmarkASCIISetscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/BenchmarkASCIISet().(b *testingscip-go gomod github.com/golang/go/src go1.11 testing/.Bscip-go gomod github.com/golang/go/src go1.11 testing/B#) {
55 b.Runscip-go gomod github.com/golang/go/src go1.11 testing/B#Run().("ASCIISet Add()", func(b *testingscip-go gomod github.com/golang/go/src go1.11 testing/.Bscip-go gomod github.com/golang/go/src go1.11 testing/B#) {
56 sets := setupASCIISetsscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/setupASCIISets().(Nscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/N., false)
57 b.ResetTimerscip-go gomod github.com/golang/go/src go1.11 testing/B#ResetTimer().()
58 for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.11 testing/B#N.; i++ {
59 for _, as := range sets {
60 for c := byte(0); c < utf8scip-go gomod github.com/golang/go/src go1.11 `unicode/utf8`/.RuneSelfscip-go gomod github.com/golang/go/src go1.11 `unicode/utf8`/RuneSelf.; c += 2 {
61 // add every 2nd ASCII character
62 as.Addscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/ASCIISet#Add().(c)
63 }
64 }
65 }
66 })
67 b.Runscip-go gomod github.com/golang/go/src go1.11 testing/B#Run().("ASCIISet Contains()", func(b *testingscip-go gomod github.com/golang/go/src go1.11 testing/.Bscip-go gomod github.com/golang/go/src go1.11 testing/B#) {
68 sets := setupASCIISetsscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/setupASCIISets().(Nscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/N., true)
69 var exists bool
70 b.ResetTimerscip-go gomod github.com/golang/go/src go1.11 testing/B#ResetTimer().()
71 for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.11 testing/B#N.; i++ {
72 for _, as := range sets {
73 for c := byte(0); c < utf8scip-go gomod github.com/golang/go/src go1.11 `unicode/utf8`/.RuneSelfscip-go gomod github.com/golang/go/src go1.11 `unicode/utf8`/RuneSelf.; c++ {
74 exists = as.Containsscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/ASCIISet#Contains().(c)
75 }
76 }
77 }
78 globalExistsscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/globalExists. = exists
79 })
80 b.Runscip-go gomod github.com/golang/go/src go1.11 testing/B#Run().("ASCIISet Remove()", func(b *testingscip-go gomod github.com/golang/go/src go1.11 testing/.Bscip-go gomod github.com/golang/go/src go1.11 testing/B#) {
81 sets := setupASCIISetsscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/setupASCIISets().(Nscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/N., true)
82 b.ResetTimerscip-go gomod github.com/golang/go/src go1.11 testing/B#ResetTimer().()
83 for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.11 testing/B#N.; i++ {
84 for _, as := range sets {
85 for c := byte(0); c < utf8scip-go gomod github.com/golang/go/src go1.11 `unicode/utf8`/.RuneSelfscip-go gomod github.com/golang/go/src go1.11 `unicode/utf8`/RuneSelf.; c++ {
86 as.Removescip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/ASCIISet#Remove().(c)
87 }
88 }
89 }
90 })
91 b.Runscip-go gomod github.com/golang/go/src go1.11 testing/B#Run().("ASCIISet Size()", func(b *testingscip-go gomod github.com/golang/go/src go1.11 testing/.Bscip-go gomod github.com/golang/go/src go1.11 testing/B#) {
92 sets := setupASCIISetsscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/setupASCIISets().(Nscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/N., true)
93 var size int
94 b.ResetTimerscip-go gomod github.com/golang/go/src go1.11 testing/B#ResetTimer().()
95 for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.11 testing/B#N.; i++ {
96 for _, as := range sets {
97 for c := byte(0); c < utf8scip-go gomod github.com/golang/go/src go1.11 `unicode/utf8`/.RuneSelfscip-go gomod github.com/golang/go/src go1.11 `unicode/utf8`/RuneSelf.; c++ {
98 size = as.Sizescip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/ASCIISet#Size().()
99 }
100 }
101 }
102 globalSizescip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/globalSize. = size
103 })
104 b.Runscip-go gomod github.com/golang/go/src go1.11 testing/B#Run().("ASCIISet Visit()", func(b *testingscip-go gomod github.com/golang/go/src go1.11 testing/.Bscip-go gomod github.com/golang/go/src go1.11 testing/B#) {
105 sets := setupASCIISetsscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/setupASCIISets().(Nscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/N., true)
106 var val byte
107 b.ResetTimerscip-go gomod github.com/golang/go/src go1.11 testing/B#ResetTimer().()
108 for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.11 testing/B#N.; i++ {
109 for _, as := range sets {
110 as.Visitscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/ASCIISet#Visit().(func(c byte) bool {
111 val = c
112 return false
113 })
114 }
115 }
116 globalValscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/globalVal. = val
117 })
118 }
119
120 func BenchmarkMapSetscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/BenchmarkMapSet().(b *testingscip-go gomod github.com/golang/go/src go1.11 testing/.Bscip-go gomod github.com/golang/go/src go1.11 testing/B#) {
121 b.Runscip-go gomod github.com/golang/go/src go1.11 testing/B#Run().("map Add", func(b *testingscip-go gomod github.com/golang/go/src go1.11 testing/.Bscip-go gomod github.com/golang/go/src go1.11 testing/B#) {
122 sets := setupMapSetsscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/setupMapSets().(Nscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/N., false)
123 b.ResetTimerscip-go gomod github.com/golang/go/src go1.11 testing/B#ResetTimer().()
124 for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.11 testing/B#N.; i++ {
125 for _, as := range sets {
126 for c := byte(0); c < utf8scip-go gomod github.com/golang/go/src go1.11 `unicode/utf8`/.RuneSelfscip-go gomod github.com/golang/go/src go1.11 `unicode/utf8`/RuneSelf.; c += 2 {
127 // add every 2nd ASCII character
128 as[c] = struct{}{}
129 }
130 }
131 }
132 })
133 b.Runscip-go gomod github.com/golang/go/src go1.11 testing/B#Run().("map Contains", func(b *testingscip-go gomod github.com/golang/go/src go1.11 testing/.Bscip-go gomod github.com/golang/go/src go1.11 testing/B#) {
134 sets := setupMapSetsscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/setupMapSets().(Nscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/N., true)
135 var exists bool
136 b.ResetTimerscip-go gomod github.com/golang/go/src go1.11 testing/B#ResetTimer().()
137 for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.11 testing/B#N.; i++ {
138 for _, as := range sets {
139 for c := byte(0); c < utf8scip-go gomod github.com/golang/go/src go1.11 `unicode/utf8`/.RuneSelfscip-go gomod github.com/golang/go/src go1.11 `unicode/utf8`/RuneSelf.; c++ {
140 _, exists = as[c]
141 }
142 }
143 }
144 globalExistsscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/globalExists. = exists
145 })
146 b.Runscip-go gomod github.com/golang/go/src go1.11 testing/B#Run().("map Remove", func(b *testingscip-go gomod github.com/golang/go/src go1.11 testing/.Bscip-go gomod github.com/golang/go/src go1.11 testing/B#) {
147 sets := setupMapSetsscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/setupMapSets().(Nscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/N., true)
148 b.ResetTimerscip-go gomod github.com/golang/go/src go1.11 testing/B#ResetTimer().()
149 for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.11 testing/B#N.; i++ {
150 for _, as := range sets {
151 for c := byte(0); c < utf8scip-go gomod github.com/golang/go/src go1.11 `unicode/utf8`/.RuneSelfscip-go gomod github.com/golang/go/src go1.11 `unicode/utf8`/RuneSelf.; c++ {
152 delete(as, c)
153 }
154 }
155 }
156 })
157 b.Runscip-go gomod github.com/golang/go/src go1.11 testing/B#Run().("map Size", func(b *testingscip-go gomod github.com/golang/go/src go1.11 testing/.Bscip-go gomod github.com/golang/go/src go1.11 testing/B#) {
158 sets := setupMapSetsscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/setupMapSets().(Nscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/N., true)
159 var size int
160 b.ResetTimerscip-go gomod github.com/golang/go/src go1.11 testing/B#ResetTimer().()
161 for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.11 testing/B#N.; i++ {
162 for _, as := range sets {
163 for c := byte(0); c < utf8scip-go gomod github.com/golang/go/src go1.11 `unicode/utf8`/.RuneSelfscip-go gomod github.com/golang/go/src go1.11 `unicode/utf8`/RuneSelf.; c++ {
164 size = len(as)
165 }
166 }
167 }
168 globalSizescip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/globalSize. = size
169 })
170 b.Runscip-go gomod github.com/golang/go/src go1.11 testing/B#Run().("map Visit", func(b *testingscip-go gomod github.com/golang/go/src go1.11 testing/.Bscip-go gomod github.com/golang/go/src go1.11 testing/B#) {
171 sets := setupMapSetsscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/setupMapSets().(Nscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/N., true)
172 var val byte
173 b.ResetTimerscip-go gomod github.com/golang/go/src go1.11 testing/B#ResetTimer().()
174 for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.11 testing/B#N.; i++ {
175 for _, as := range sets {
176 for c := range as {
177 val = c
178 }
179 }
180 }
181 globalValscip-go gomod github.com/elliotwutingfeng/asciiset . `github.com/elliotwutingfeng/asciiset`/globalVal. = val
182 })
183 }