Skip to content

Commit f7f7569

Browse files
committed
add benchmarks
1 parent 3b90586 commit f7f7569

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

benchmarks_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package validator
33
import (
44
"bytes"
55
sql "database/sql/driver"
6+
"errors"
67
"testing"
78
"time"
89
)
@@ -1097,3 +1098,39 @@ func BenchmarkOneofParallel(b *testing.B) {
10971098
}
10981099
})
10991100
}
1101+
1102+
type T struct{}
1103+
1104+
func (*T) Validate() error { return errors.New("ops") }
1105+
1106+
func BenchmarkValidateFnSequencial(b *testing.B) {
1107+
validate := New()
1108+
1109+
type Test struct {
1110+
T T `validate:"validateFn"`
1111+
}
1112+
1113+
test := &Test{}
1114+
1115+
b.ResetTimer()
1116+
for n := 0; n < b.N; n++ {
1117+
_ = validate.Struct(test)
1118+
}
1119+
}
1120+
1121+
func BenchmarkValidateFnParallel(b *testing.B) {
1122+
validate := New()
1123+
1124+
type Test struct {
1125+
T T `validate:"validateFn"`
1126+
}
1127+
1128+
test := &Test{}
1129+
1130+
b.ResetTimer()
1131+
b.RunParallel(func(pb *testing.PB) {
1132+
for pb.Next() {
1133+
_ = validate.Struct(test)
1134+
}
1135+
})
1136+
}

0 commit comments

Comments
 (0)