Debian Codegraph @

zapcore/sampler_bench_test.go

raw symbols SCIP
1 // Copyright (c) 2016 Uber Technologies, Inc.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20
21 package zapcore_testscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore_test`/
22
23 import (
24 "fmtscip-go gomod github.com/golang/go/src go1.19 fmt/"
25 "sync/atomicscip-go gomod github.com/golang/go/src go1.19 `sync/atomic`/"
26 "testingscip-go gomod github.com/golang/go/src go1.19 testing/"
27 "timescip-go gomod github.com/golang/go/src go1.19 time/"
28
29 "github.com/stretchr/testify/assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/"
30 "go.uber.org/zap/internal/ztestscip-go gomod go.uber.org/zap . `go.uber.org/zap/internal/ztest`/"
31
32 //revive:disable:dot-imports
33 . "go.uber.org/zap/zapcorescip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/"
34 )
35
36 var counterTestCasesscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore_test`/counterTestCases. = [][]string{
37 // some stuff I made up
38 {
39 "foo",
40 "bar",
41 "baz",
42 "alpha",
43 "bravo",
44 "charlie",
45 "delta",
46 },
47
48 // shuf -n50 /usr/share/dict/words
49 {
50 "unbracing",
51 "stereotomy",
52 "supranervian",
53 "moaning",
54 "exchangeability",
55 "gunyang",
56 "sulcation",
57 "dariole",
58 "archheresy",
59 "synchronistically",
60 "clips",
61 "unsanctioned",
62 "Argoan",
63 "liparomphalus",
64 "layship",
65 "Fregatae",
66 "microzoology",
67 "glaciaria",
68 "Frugivora",
69 "patterist",
70 "Grossulariaceae",
71 "lithotint",
72 "bargander",
73 "opisthographical",
74 "cacography",
75 "chalkstone",
76 "nonsubstantialism",
77 "sardonicism",
78 "calamiform",
79 "lodginghouse",
80 "predisposedly",
81 "topotypic",
82 "broideress",
83 "outrange",
84 "gingivolabial",
85 "monoazo",
86 "sparlike",
87 "concameration",
88 "untoothed",
89 "Camorrism",
90 "reissuer",
91 "soap",
92 "palaiotype",
93 "countercharm",
94 "yellowbird",
95 "palterly",
96 "writinger",
97 "boatfalls",
98 "tuglike",
99 "underbitten",
100 },
101
102 // shuf -n100 /usr/share/dict/words
103 {
104 "rooty",
105 "malcultivation",
106 "degrade",
107 "pseudoindependent",
108 "stillatory",
109 "antiseptize",
110 "protoamphibian",
111 "antiar",
112 "Esther",
113 "pseudelminth",
114 "superfluitance",
115 "teallite",
116 "disunity",
117 "spirignathous",
118 "vergency",
119 "myliobatid",
120 "inosic",
121 "overabstemious",
122 "patriarchally",
123 "foreimagine",
124 "coetaneity",
125 "hemimellitene",
126 "hyperspatial",
127 "aulophyte",
128 "electropoion",
129 "antitrope",
130 "Amarantus",
131 "smaltine",
132 "lighthead",
133 "syntonically",
134 "incubous",
135 "versation",
136 "cirsophthalmia",
137 "Ulidian",
138 "homoeography",
139 "Velella",
140 "Hecatean",
141 "serfage",
142 "Spermaphyta",
143 "palatoplasty",
144 "electroextraction",
145 "aconite",
146 "avirulence",
147 "initiator",
148 "besmear",
149 "unrecognizably",
150 "euphoniousness",
151 "balbuties",
152 "pascuage",
153 "quebracho",
154 "Yakala",
155 "auriform",
156 "sevenbark",
157 "superorganism",
158 "telesterion",
159 "ensand",
160 "nagaika",
161 "anisuria",
162 "etching",
163 "soundingly",
164 "grumpish",
165 "drillmaster",
166 "perfumed",
167 "dealkylate",
168 "anthracitiferous",
169 "predefiance",
170 "sulphoxylate",
171 "freeness",
172 "untucking",
173 "misworshiper",
174 "Nestorianize",
175 "nonegoistical",
176 "construe",
177 "upstroke",
178 "teated",
179 "nasolachrymal",
180 "Mastodontidae",
181 "gallows",
182 "radioluminescent",
183 "uncourtierlike",
184 "phasmatrope",
185 "Clunisian",
186 "drainage",
187 "sootless",
188 "brachyfacial",
189 "antiheroism",
190 "irreligionize",
191 "ked",
192 "unfact",
193 "nonprofessed",
194 "milady",
195 "conjecture",
196 "Arctomys",
197 "guapilla",
198 "Sassenach",
199 "emmetrope",
200 "rosewort",
201 "raphidiferous",
202 "pooh",
203 "Tyndallize",
204 },
205 }
206
207 func BenchmarkSampler_Checkscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore_test`/BenchmarkSampler_Check().(b *testingscip-go gomod github.com/golang/go/src go1.19 testing/.Bscip-go gomod github.com/golang/go/src go1.19 testing/B#) {
208 for _, keys := range counterTestCasesscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore_test`/counterTestCases. {
209 b.Runscip-go gomod github.com/golang/go/src go1.19 testing/B#Run().(fmtscip-go gomod github.com/golang/go/src go1.19 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.19 fmt/Sprintf().("%v keys", len(keys)), func(b *testingscip-go gomod github.com/golang/go/src go1.19 testing/.Bscip-go gomod github.com/golang/go/src go1.19 testing/B#) {
210 fac := NewSamplerWithOptionsscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/NewSamplerWithOptions().(
211 NewCorescip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/NewCore().(
212 NewJSONEncoderscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/NewJSONEncoder().(testEncoderConfigscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore_test`/testEncoderConfig().()),
213 &ztestscip-go gomod go.uber.org/zap . `go.uber.org/zap/internal/ztest`/.Discarderscip-go gomod go.uber.org/zap . `go.uber.org/zap/internal/ztest`/Discarder#{},
214 DebugLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/DebugLevel.,
215 ),
216 timescip-go gomod github.com/golang/go/src go1.19 time/.Millisecondscip-go gomod github.com/golang/go/src go1.19 time/Millisecond., 1, 1000)
217 b.ResetTimerscip-go gomod github.com/golang/go/src go1.19 testing/B#ResetTimer().()
218 b.RunParallelscip-go gomod github.com/golang/go/src go1.19 testing/B#RunParallel().(func(pb *testingscip-go gomod github.com/golang/go/src go1.19 testing/.PBscip-go gomod github.com/golang/go/src go1.19 testing/PB#) {
219 i := 0
220 for pb.Nextscip-go gomod github.com/golang/go/src go1.19 testing/PB#Next().() {
221 ent := Entryscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Entry#{
222 Levelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Entry#Level.: DebugLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/DebugLevel. + Levelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#(i%4),
223 Messagescip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Entry#Message.: keys[i],
224 }
225 _ = fac.Checkscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Core#Check.(ent, nil)
226 i++
227 if n := len(keys); i >= n {
228 i -= n
229 }
230 }
231 })
232 })
233 }
234 }
235
236 func makeSamplerCountingHookscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore_test`/makeSamplerCountingHook().() (func(_ Entryscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Entry#, dec SamplingDecisionscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/SamplingDecision#), *atomicscip-go gomod github.com/golang/go/src go1.19 `sync/atomic`/.Int64scip-go gomod github.com/golang/go/src go1.19 `sync/atomic`/Int64#, *atomicscip-go gomod github.com/golang/go/src go1.19 `sync/atomic`/.Int64scip-go gomod github.com/golang/go/src go1.19 `sync/atomic`/Int64#) {
237 droppedCount := new(atomicscip-go gomod github.com/golang/go/src go1.19 `sync/atomic`/.Int64scip-go gomod github.com/golang/go/src go1.19 `sync/atomic`/Int64#)
238 sampledCount := new(atomicscip-go gomod github.com/golang/go/src go1.19 `sync/atomic`/.Int64scip-go gomod github.com/golang/go/src go1.19 `sync/atomic`/Int64#)
239 h := func(_ Entryscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Entry#, dec SamplingDecisionscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/SamplingDecision#) {
240 if dec&LogDroppedscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/LogDropped. > 0 {
241 droppedCount.Addscip-go gomod github.com/golang/go/src go1.19 `sync/atomic`/Int64#Add().(1)
242 } else if dec&LogSampledscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/LogSampled. > 0 {
243 sampledCount.Addscip-go gomod github.com/golang/go/src go1.19 `sync/atomic`/Int64#Add().(1)
244 }
245 }
246 return h, droppedCount, sampledCount
247 }
248
249 func BenchmarkSampler_CheckWithHookscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore_test`/BenchmarkSampler_CheckWithHook().(b *testingscip-go gomod github.com/golang/go/src go1.19 testing/.Bscip-go gomod github.com/golang/go/src go1.19 testing/B#) {
250 hook, dropped, sampled := makeSamplerCountingHookscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore_test`/makeSamplerCountingHook().()
251 for _, keys := range counterTestCasesscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore_test`/counterTestCases. {
252 b.Runscip-go gomod github.com/golang/go/src go1.19 testing/B#Run().(fmtscip-go gomod github.com/golang/go/src go1.19 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.19 fmt/Sprintf().("%v keys", len(keys)), func(b *testingscip-go gomod github.com/golang/go/src go1.19 testing/.Bscip-go gomod github.com/golang/go/src go1.19 testing/B#) {
253 fac := NewSamplerWithOptionsscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/NewSamplerWithOptions().(
254 NewCorescip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/NewCore().(
255 NewJSONEncoderscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/NewJSONEncoder().(testEncoderConfigscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore_test`/testEncoderConfig().()),
256 &ztestscip-go gomod go.uber.org/zap . `go.uber.org/zap/internal/ztest`/.Discarderscip-go gomod go.uber.org/zap . `go.uber.org/zap/internal/ztest`/Discarder#{},
257 DebugLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/DebugLevel.,
258 ),
259 timescip-go gomod github.com/golang/go/src go1.19 time/.Millisecondscip-go gomod github.com/golang/go/src go1.19 time/Millisecond.,
260 1,
261 1000,
262 SamplerHookscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/SamplerHook().(hook),
263 )
264 b.ResetTimerscip-go gomod github.com/golang/go/src go1.19 testing/B#ResetTimer().()
265 b.RunParallelscip-go gomod github.com/golang/go/src go1.19 testing/B#RunParallel().(func(pb *testingscip-go gomod github.com/golang/go/src go1.19 testing/.PBscip-go gomod github.com/golang/go/src go1.19 testing/PB#) {
266 i := 0
267 for pb.Nextscip-go gomod github.com/golang/go/src go1.19 testing/PB#Next().() {
268 ent := Entryscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Entry#{
269 Levelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Entry#Level.: DebugLevelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/DebugLevel. + Levelscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Level#(i%4),
270 Messagescip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Entry#Message.: keys[i],
271 }
272 _ = fac.Checkscip-go gomod go.uber.org/zap . `go.uber.org/zap/zapcore`/Core#Check.(ent, nil)
273 i++
274 if n := len(keys); i >= n {
275 i -= n
276 }
277 }
278 })
279 // We expect to see 1000 dropped messages for every sampled per settings,
280 // with a delta due to less 1000 messages getting dropped after initial one
281 // is sampled.
282 assertscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/.Greaterscip-go gomod github.com/stretchr/testify v1.8.1 `github.com/stretchr/testify/assert`/Greater().(b, dropped.Loadscip-go gomod github.com/golang/go/src go1.19 `sync/atomic`/Int64#Load().()/1000, sampled.Loadscip-go gomod github.com/golang/go/src go1.19 `sync/atomic`/Int64#Load().()-1000)
283 dropped.Storescip-go gomod github.com/golang/go/src go1.19 `sync/atomic`/Int64#Store().(0)
284 sampled.Storescip-go gomod github.com/golang/go/src go1.19 `sync/atomic`/Int64#Store().(0)
285 })
286 }
287 }