@@ -2325,45 +2325,8 @@ func BenchmarkValidateField(b *testing.B) {
23252325 }
23262326}
23272327
2328- func BenchmarkValidateStruct (b * testing.B ) {
2329-
2330- // type Inner struct {
2331-
2332- // }
2333-
2334- // type Test struct {
2335- // StringVal string `bson:"required,lt=10"`
2336- // Int64Val int64 `bson:"gt=0,lt=10"`
2337- // }
2338-
2339- // tFail := &TestString{
2340- // Required: "",
2341- // Len: "",
2342- // Min: "",
2343- // Max: "12345678901",
2344- // MinMax: "",
2345- // Lt: "0123456789",
2346- // Lte: "01234567890",
2347- // Gt: "1",
2348- // Gte: "1",
2349- // OmitEmpty: "12345678901",
2350- // Sub: &SubTest{
2351- // Test: "",
2352- // },
2353- // Anonymous: struct {
2354- // A string `validate:"required"`
2355- // }{
2356- // A: "",
2357- // },
2358- // Iface: &Impl{
2359- // F: "12",
2360- // },
2361- // }
2362-
2363- // t := &Test{
2364- // StringVal: "test",
2365- // Int64Val: 5,
2366- // }
2328+ func BenchmarkValidateStructSimple (b * testing.B ) {
2329+
23672330 type Foo struct {
23682331 StringValue string `validate:"min=5,max=10"`
23692332 IntValue int `validate:"min=5,max=10"`
@@ -2378,7 +2341,7 @@ func BenchmarkValidateStruct(b *testing.B) {
23782341 }
23792342}
23802343
2381- func BenchmarkTemplateParallel (b * testing.B ) {
2344+ func BenchmarkTemplateParallelSimple (b * testing.B ) {
23822345
23832346 type Foo struct {
23842347 StringValue string `validate:"min=5,max=10"`
@@ -2395,3 +2358,123 @@ func BenchmarkTemplateParallel(b *testing.B) {
23952358 }
23962359 })
23972360}
2361+
2362+ func BenchmarkValidateStructLarge (b * testing.B ) {
2363+
2364+ tFail := & TestString {
2365+ Required : "" ,
2366+ Len : "" ,
2367+ Min : "" ,
2368+ Max : "12345678901" ,
2369+ MinMax : "" ,
2370+ Lt : "0123456789" ,
2371+ Lte : "01234567890" ,
2372+ Gt : "1" ,
2373+ Gte : "1" ,
2374+ OmitEmpty : "12345678901" ,
2375+ Sub : & SubTest {
2376+ Test : "" ,
2377+ },
2378+ Anonymous : struct {
2379+ A string `validate:"required"`
2380+ }{
2381+ A : "" ,
2382+ },
2383+ Iface : & Impl {
2384+ F : "12" ,
2385+ },
2386+ }
2387+
2388+ tSuccess := & TestString {
2389+ Required : "Required" ,
2390+ Len : "length==10" ,
2391+ Min : "min=1" ,
2392+ Max : "1234567890" ,
2393+ MinMax : "12345" ,
2394+ Lt : "012345678" ,
2395+ Lte : "0123456789" ,
2396+ Gt : "01234567890" ,
2397+ Gte : "0123456789" ,
2398+ OmitEmpty : "" ,
2399+ Sub : & SubTest {
2400+ Test : "1" ,
2401+ },
2402+ SubIgnore : & SubTest {
2403+ Test : "" ,
2404+ },
2405+ Anonymous : struct {
2406+ A string `validate:"required"`
2407+ }{
2408+ A : "1" ,
2409+ },
2410+ Iface : & Impl {
2411+ F : "123" ,
2412+ },
2413+ }
2414+
2415+ for n := 0 ; n < b .N ; n ++ {
2416+ validate .Struct (tSuccess )
2417+ validate .Struct (tFail )
2418+ }
2419+ }
2420+
2421+ func BenchmarkTemplateParallelLarge (b * testing.B ) {
2422+
2423+ tFail := & TestString {
2424+ Required : "" ,
2425+ Len : "" ,
2426+ Min : "" ,
2427+ Max : "12345678901" ,
2428+ MinMax : "" ,
2429+ Lt : "0123456789" ,
2430+ Lte : "01234567890" ,
2431+ Gt : "1" ,
2432+ Gte : "1" ,
2433+ OmitEmpty : "12345678901" ,
2434+ Sub : & SubTest {
2435+ Test : "" ,
2436+ },
2437+ Anonymous : struct {
2438+ A string `validate:"required"`
2439+ }{
2440+ A : "" ,
2441+ },
2442+ Iface : & Impl {
2443+ F : "12" ,
2444+ },
2445+ }
2446+
2447+ tSuccess := & TestString {
2448+ Required : "Required" ,
2449+ Len : "length==10" ,
2450+ Min : "min=1" ,
2451+ Max : "1234567890" ,
2452+ MinMax : "12345" ,
2453+ Lt : "012345678" ,
2454+ Lte : "0123456789" ,
2455+ Gt : "01234567890" ,
2456+ Gte : "0123456789" ,
2457+ OmitEmpty : "" ,
2458+ Sub : & SubTest {
2459+ Test : "1" ,
2460+ },
2461+ SubIgnore : & SubTest {
2462+ Test : "" ,
2463+ },
2464+ Anonymous : struct {
2465+ A string `validate:"required"`
2466+ }{
2467+ A : "1" ,
2468+ },
2469+ Iface : & Impl {
2470+ F : "123" ,
2471+ },
2472+ }
2473+
2474+ b .RunParallel (func (pb * testing.PB ) {
2475+ for pb .Next () {
2476+ validate .Struct (tSuccess )
2477+ validate .Struct (tFail )
2478+ }
2479+ })
2480+ }
0 commit comments