-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassert_bench_test.go
More file actions
229 lines (196 loc) · 4.16 KB
/
Copy pathassert_bench_test.go
File metadata and controls
229 lines (196 loc) · 4.16 KB
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
// SPDX-License-Identifier: EUPL-1.2
// Benchmarks for the assertion helpers in assert.go. Each benchmark
// drives the success path (the predicate holds, so no t.Error/Fatal
// fires) — that is the cost every passing test pays, and the core test
// suite runs tens of thousands of these. The `any` parameters box, so
// these numbers also track the reflect/interface overhead of the
// comparison helpers.
//
// Run: go test -bench='BenchmarkAssert|BenchmarkRequire' -benchmem -run='^$' .
package core_test
import (
. "dappco.re/go"
)
func BenchmarkAssertEqual(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertEqual(b, 42, 42)
}
}
func BenchmarkAssertNotEqual(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertNotEqual(b, 1, 2)
}
}
func BenchmarkAssertTrue(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertTrue(b, true)
}
}
func BenchmarkAssertFalse(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertFalse(b, false)
}
}
func BenchmarkAssertNil(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertNil(b, nil)
}
}
func BenchmarkAssertNotNil(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertNotNil(b, "ready")
}
}
func BenchmarkAssertNoError(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertNoError(b, nil)
}
}
func BenchmarkAssertError(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertError(b, AnError)
}
}
func BenchmarkAssertContains(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertContains(b, "agent ready", "ready")
}
}
func BenchmarkAssertNotContains(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertNotContains(b, "agent ready", "offline")
}
}
func BenchmarkAssertLen(b *B) {
v := []int{1, 2, 3}
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertLen(b, v, 3)
}
}
func BenchmarkAssertEmpty(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertEmpty(b, "")
}
}
func BenchmarkAssertNotEmpty(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertNotEmpty(b, "x")
}
}
func BenchmarkAssertGreater(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertGreater(b, 5, 3)
}
}
func BenchmarkAssertGreaterOrEqual(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertGreaterOrEqual(b, 5, 5)
}
}
func BenchmarkAssertLess(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertLess(b, 3, 5)
}
}
func BenchmarkAssertLessOrEqual(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertLessOrEqual(b, 5, 5)
}
}
func BenchmarkAssertPanics(b *B) {
fn := func() { panic("boom") }
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertPanics(b, fn)
}
}
func BenchmarkAssertNotPanics(b *B) {
fn := func() {}
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertNotPanics(b, fn)
}
}
func BenchmarkAssertPanicsWithError(b *B) {
fn := func() { panic(NewError("boom token")) }
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertPanicsWithError(b, "boom", fn)
}
}
func BenchmarkAssertErrorIs(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertErrorIs(b, AnError, AnError)
}
}
func BenchmarkAssertInDelta(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertInDelta(b, 1.0, 1.0, 0.01)
}
}
func BenchmarkAssertSame(b *B) {
p := &struct{ n int }{n: 1}
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertSame(b, p, p)
}
}
func BenchmarkAssertElementsMatch(b *B) {
want := []int{1, 2, 3}
got := []int{3, 2, 1}
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertElementsMatch(b, want, got)
}
}
func BenchmarkRequireNoError(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
RequireNoError(b, nil)
}
}
func BenchmarkRequireTrue(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
RequireTrue(b, true)
}
}
func BenchmarkRequireNotEmpty(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
RequireNotEmpty(b, "x")
}
}
// Typed comparisons drive the uint64 / float64 branches of the ordering
// helpers (assertCmpUint64 / assertCmpFloat64).
func BenchmarkAssertGreater_Uint64(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertGreater(b, uint64(5), uint64(3))
}
}
func BenchmarkAssertGreater_Float64(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
AssertGreater(b, 5.0, 3.0)
}
}