-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbench_test.go
44 lines (39 loc) · 1.01 KB
/
bench_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
package validator
import "testing"
type BenchTestStruct struct {
Name string `json:"name" constraints:"min-length=5"`
Age int `json:"age" constraints:"min=21"`
Description string `json:"description" constraints:"max-length=50"`
Cost float64 `json:"cost" constraints:"exclusiveMin=200"`
ItemCount int `json:"itemCount" constraints:"multipleOf=5"`
}
func BenchmarkValidator(b *testing.B) {
msg := BenchTestStruct{
Name: "BenchTest",
Age: 25,
Description: "this is bench testing",
Cost: 299.9,
ItemCount: 2000,
}
sv := NewStructValidator()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = sv.Validate(msg)
}
}
func BenchmarkValidatorParallel(b *testing.B) {
msg := BenchTestStruct{
Name: "BenchTest",
Age: 25,
Description: "this is bench testing",
Cost: 299.9,
ItemCount: 2000,
}
sv := NewStructValidator()
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_ = sv.Validate(msg)
}
})
}