From 56b4ce18117f195c19bc6cf94fabb3552e7207c6 Mon Sep 17 00:00:00 2001 From: joeybloggs Date: Sun, 7 Jun 2015 23:57:32 -0400 Subject: [PATCH] add larger tests for benchmarks --- validator_test.go | 163 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 123 insertions(+), 40 deletions(-) diff --git a/validator_test.go b/validator_test.go index aed06a9..268ddd6 100644 --- a/validator_test.go +++ b/validator_test.go @@ -2325,45 +2325,8 @@ func BenchmarkValidateField(b *testing.B) { } } -func BenchmarkValidateStruct(b *testing.B) { - - // type Inner struct { - - // } - - // type Test struct { - // StringVal string `bson:"required,lt=10"` - // Int64Val int64 `bson:"gt=0,lt=10"` - // } - - // tFail := &TestString{ - // Required: "", - // Len: "", - // Min: "", - // Max: "12345678901", - // MinMax: "", - // Lt: "0123456789", - // Lte: "01234567890", - // Gt: "1", - // Gte: "1", - // OmitEmpty: "12345678901", - // Sub: &SubTest{ - // Test: "", - // }, - // Anonymous: struct { - // A string `validate:"required"` - // }{ - // A: "", - // }, - // Iface: &Impl{ - // F: "12", - // }, - // } - - // t := &Test{ - // StringVal: "test", - // Int64Val: 5, - // } +func BenchmarkValidateStructSimple(b *testing.B) { + type Foo struct { StringValue string `validate:"min=5,max=10"` IntValue int `validate:"min=5,max=10"` @@ -2378,7 +2341,7 @@ func BenchmarkValidateStruct(b *testing.B) { } } -func BenchmarkTemplateParallel(b *testing.B) { +func BenchmarkTemplateParallelSimple(b *testing.B) { type Foo struct { StringValue string `validate:"min=5,max=10"` @@ -2395,3 +2358,123 @@ func BenchmarkTemplateParallel(b *testing.B) { } }) } + +func BenchmarkValidateStructLarge(b *testing.B) { + + tFail := &TestString{ + Required: "", + Len: "", + Min: "", + Max: "12345678901", + MinMax: "", + Lt: "0123456789", + Lte: "01234567890", + Gt: "1", + Gte: "1", + OmitEmpty: "12345678901", + Sub: &SubTest{ + Test: "", + }, + Anonymous: struct { + A string `validate:"required"` + }{ + A: "", + }, + Iface: &Impl{ + F: "12", + }, + } + + tSuccess := &TestString{ + Required: "Required", + Len: "length==10", + Min: "min=1", + Max: "1234567890", + MinMax: "12345", + Lt: "012345678", + Lte: "0123456789", + Gt: "01234567890", + Gte: "0123456789", + OmitEmpty: "", + Sub: &SubTest{ + Test: "1", + }, + SubIgnore: &SubTest{ + Test: "", + }, + Anonymous: struct { + A string `validate:"required"` + }{ + A: "1", + }, + Iface: &Impl{ + F: "123", + }, + } + + for n := 0; n < b.N; n++ { + validate.Struct(tSuccess) + validate.Struct(tFail) + } +} + +func BenchmarkTemplateParallelLarge(b *testing.B) { + + tFail := &TestString{ + Required: "", + Len: "", + Min: "", + Max: "12345678901", + MinMax: "", + Lt: "0123456789", + Lte: "01234567890", + Gt: "1", + Gte: "1", + OmitEmpty: "12345678901", + Sub: &SubTest{ + Test: "", + }, + Anonymous: struct { + A string `validate:"required"` + }{ + A: "", + }, + Iface: &Impl{ + F: "12", + }, + } + + tSuccess := &TestString{ + Required: "Required", + Len: "length==10", + Min: "min=1", + Max: "1234567890", + MinMax: "12345", + Lt: "012345678", + Lte: "0123456789", + Gt: "01234567890", + Gte: "0123456789", + OmitEmpty: "", + Sub: &SubTest{ + Test: "1", + }, + SubIgnore: &SubTest{ + Test: "", + }, + Anonymous: struct { + A string `validate:"required"` + }{ + A: "1", + }, + Iface: &Impl{ + F: "123", + }, + } + + b.RunParallel(func(pb *testing.PB) { + for pb.Next() { + validate.Struct(tSuccess) + validate.Struct(tFail) + } + }) +}