PageRenderTime 24ms CodeModel.GetById 14ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/Godeps/_workspace/src/gopkg.in/bluesuncorp/validator.v5/benchmarks_test.go

https://gitlab.com/voxxit/gogeoip2
Go | 163 lines | 145 code | 18 blank | 0 comment | 5 complexity | 3603ff5cdbf9b58236894e783ec3cf5c MD5 | raw file
  1package validator
  2
  3import "testing"
  4
  5func BenchmarkValidateField(b *testing.B) {
  6	for n := 0; n < b.N; n++ {
  7		validate.Field("1", "len=1")
  8	}
  9}
 10
 11func BenchmarkValidateStructSimple(b *testing.B) {
 12
 13	type Foo struct {
 14		StringValue string `validate:"min=5,max=10"`
 15		IntValue    int    `validate:"min=5,max=10"`
 16	}
 17
 18	validFoo := &Foo{StringValue: "Foobar", IntValue: 7}
 19	invalidFoo := &Foo{StringValue: "Fo", IntValue: 3}
 20
 21	for n := 0; n < b.N; n++ {
 22		validate.Struct(validFoo)
 23		validate.Struct(invalidFoo)
 24	}
 25}
 26
 27func BenchmarkTemplateParallelSimple(b *testing.B) {
 28
 29	type Foo struct {
 30		StringValue string `validate:"min=5,max=10"`
 31		IntValue    int    `validate:"min=5,max=10"`
 32	}
 33
 34	validFoo := &Foo{StringValue: "Foobar", IntValue: 7}
 35	invalidFoo := &Foo{StringValue: "Fo", IntValue: 3}
 36
 37	b.RunParallel(func(pb *testing.PB) {
 38		for pb.Next() {
 39			validate.Struct(validFoo)
 40			validate.Struct(invalidFoo)
 41		}
 42	})
 43}
 44
 45func BenchmarkValidateStructLarge(b *testing.B) {
 46
 47	tFail := &TestString{
 48		Required:  "",
 49		Len:       "",
 50		Min:       "",
 51		Max:       "12345678901",
 52		MinMax:    "",
 53		Lt:        "0123456789",
 54		Lte:       "01234567890",
 55		Gt:        "1",
 56		Gte:       "1",
 57		OmitEmpty: "12345678901",
 58		Sub: &SubTest{
 59			Test: "",
 60		},
 61		Anonymous: struct {
 62			A string `validate:"required"`
 63		}{
 64			A: "",
 65		},
 66		Iface: &Impl{
 67			F: "12",
 68		},
 69	}
 70
 71	tSuccess := &TestString{
 72		Required:  "Required",
 73		Len:       "length==10",
 74		Min:       "min=1",
 75		Max:       "1234567890",
 76		MinMax:    "12345",
 77		Lt:        "012345678",
 78		Lte:       "0123456789",
 79		Gt:        "01234567890",
 80		Gte:       "0123456789",
 81		OmitEmpty: "",
 82		Sub: &SubTest{
 83			Test: "1",
 84		},
 85		SubIgnore: &SubTest{
 86			Test: "",
 87		},
 88		Anonymous: struct {
 89			A string `validate:"required"`
 90		}{
 91			A: "1",
 92		},
 93		Iface: &Impl{
 94			F: "123",
 95		},
 96	}
 97
 98	for n := 0; n < b.N; n++ {
 99		validate.Struct(tSuccess)
100		validate.Struct(tFail)
101	}
102}
103
104func BenchmarkTemplateParallelLarge(b *testing.B) {
105
106	tFail := &TestString{
107		Required:  "",
108		Len:       "",
109		Min:       "",
110		Max:       "12345678901",
111		MinMax:    "",
112		Lt:        "0123456789",
113		Lte:       "01234567890",
114		Gt:        "1",
115		Gte:       "1",
116		OmitEmpty: "12345678901",
117		Sub: &SubTest{
118			Test: "",
119		},
120		Anonymous: struct {
121			A string `validate:"required"`
122		}{
123			A: "",
124		},
125		Iface: &Impl{
126			F: "12",
127		},
128	}
129
130	tSuccess := &TestString{
131		Required:  "Required",
132		Len:       "length==10",
133		Min:       "min=1",
134		Max:       "1234567890",
135		MinMax:    "12345",
136		Lt:        "012345678",
137		Lte:       "0123456789",
138		Gt:        "01234567890",
139		Gte:       "0123456789",
140		OmitEmpty: "",
141		Sub: &SubTest{
142			Test: "1",
143		},
144		SubIgnore: &SubTest{
145			Test: "",
146		},
147		Anonymous: struct {
148			A string `validate:"required"`
149		}{
150			A: "1",
151		},
152		Iface: &Impl{
153			F: "123",
154		},
155	}
156
157	b.RunParallel(func(pb *testing.PB) {
158		for pb.Next() {
159			validate.Struct(tSuccess)
160			validate.Struct(tFail)
161		}
162	})
163}