Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Docs. and Benchmarks #120

Merged
merged 2 commits into from
Jul 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,18 @@ hurt parallel performance too much.
```go
$ go test -cpu=4 -bench=. -benchmem=true
PASS
BenchmarkField-4 5000000 314 ns/op 16 B/op 1 allocs/op
BenchmarkFieldOrTag-4 500000 2425 ns/op 20 B/op 2 allocs/op
BenchmarkStructSimple-4 500000 3117 ns/op 553 B/op 14 allocs/op
BenchmarkStructSimpleParallel-4 1000000 1149 ns/op 553 B/op 14 allocs/op
BenchmarkStructComplex-4 100000 19580 ns/op 3230 B/op 102 allocs/op
BenchmarkStructComplexParallel-4 200000 6686 ns/op 3232 B/op 102 allocs/op
BenchmarkFieldSuccess-4 5000000 326 ns/op 16 B/op 1 allocs/op
BenchmarkFieldFailure-4 5000000 327 ns/op 16 B/op 1 allocs/op
BenchmarkFieldOrTagSuccess-4 500000 2738 ns/op 20 B/op 2 allocs/op
BenchmarkFieldOrTagFailure-4 1000000 1341 ns/op 384 B/op 6 allocs/op
BenchmarkStructSimpleSuccess-4 1000000 1282 ns/op 24 B/op 3 allocs/op
BenchmarkStructSimpleFailure-4 1000000 1870 ns/op 529 B/op 11 allocs/op
BenchmarkStructSimpleSuccessParallel-4 5000000 348 ns/op 24 B/op 3 allocs/op
BenchmarkStructSimpleFailureParallel-4 2000000 807 ns/op 529 B/op 11 allocs/op
BenchmarkStructComplexSuccess-4 200000 8081 ns/op 368 B/op 30 allocs/op
BenchmarkStructComplexFailure-4 100000 12418 ns/op 2861 B/op 72 allocs/op
BenchmarkStructComplexSuccessParallel-4 500000 2249 ns/op 369 B/op 30 allocs/op
BenchmarkStructComplexFailureParallel-4 300000 5183 ns/op 2863 B/op 72 allocs/op
```

How to Contribute
Expand Down
116 changes: 84 additions & 32 deletions benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,92 @@ package validator

import "testing"

func BenchmarkField(b *testing.B) {
func BenchmarkFieldSuccess(b *testing.B) {
for n := 0; n < b.N; n++ {
validate.Field("1", "len=1")
}
}

func BenchmarkFieldOrTag(b *testing.B) {
func BenchmarkFieldFailure(b *testing.B) {
for n := 0; n < b.N; n++ {
validate.Field("2", "len=1")
}
}

func BenchmarkFieldOrTagSuccess(b *testing.B) {
for n := 0; n < b.N; n++ {
validate.Field("rgba(0,0,0,1)", "rgb|rgba")
}
}

func BenchmarkStructSimple(b *testing.B) {
func BenchmarkFieldOrTagFailure(b *testing.B) {
for n := 0; n < b.N; n++ {
validate.Field("#000", "rgb|rgba")
}
}

func BenchmarkStructSimpleSuccess(b *testing.B) {

type Foo struct {
StringValue string `validate:"min=5,max=10"`
IntValue int `validate:"min=5,max=10"`
}

validFoo := &Foo{StringValue: "Foobar", IntValue: 7}
invalidFoo := &Foo{StringValue: "Fo", IntValue: 3}

for n := 0; n < b.N; n++ {
validate.Struct(validFoo)
}
}

func BenchmarkStructSimpleFailure(b *testing.B) {

type Foo struct {
StringValue string `validate:"min=5,max=10"`
IntValue int `validate:"min=5,max=10"`
}

invalidFoo := &Foo{StringValue: "Fo", IntValue: 3}

for n := 0; n < b.N; n++ {
validate.Struct(invalidFoo)
}
}

func BenchmarkStructSimpleParallel(b *testing.B) {
func BenchmarkStructSimpleSuccessParallel(b *testing.B) {

type Foo struct {
StringValue string `validate:"min=5,max=10"`
IntValue int `validate:"min=5,max=10"`
}

validFoo := &Foo{StringValue: "Foobar", IntValue: 7}
invalidFoo := &Foo{StringValue: "Fo", IntValue: 3}

b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
validate.Struct(validFoo)
validate.Struct(invalidFoo)
}
})
}

func BenchmarkStructComplex(b *testing.B) {
func BenchmarkStructSimpleFailureParallel(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",
},
type Foo struct {
StringValue string `validate:"min=5,max=10"`
IntValue int `validate:"min=5,max=10"`
}

invalidFoo := &Foo{StringValue: "Fo", IntValue: 3}

b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
validate.Struct(invalidFoo)
}
})
}

func BenchmarkStructComplexSuccess(b *testing.B) {

tSuccess := &TestString{
Required: "Required",
Len: "length==10",
Expand Down Expand Up @@ -103,11 +117,10 @@ func BenchmarkStructComplex(b *testing.B) {

for n := 0; n < b.N; n++ {
validate.Struct(tSuccess)
validate.Struct(tFail)
}
}

func BenchmarkStructComplexParallel(b *testing.B) {
func BenchmarkStructComplexFailure(b *testing.B) {

tFail := &TestString{
Required: "",
Expand All @@ -133,6 +146,13 @@ func BenchmarkStructComplexParallel(b *testing.B) {
},
}

for n := 0; n < b.N; n++ {
validate.Struct(tFail)
}
}

func BenchmarkStructComplexSuccessParallel(b *testing.B) {

tSuccess := &TestString{
Required: "Required",
Len: "length==10",
Expand Down Expand Up @@ -163,6 +183,38 @@ func BenchmarkStructComplexParallel(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
validate.Struct(tSuccess)
}
})
}

func BenchmarkStructComplexFailureParallel(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",
},
}

b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
validate.Struct(tFail)
}
})
Expand Down
5 changes: 0 additions & 5 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ Here is a list of the current built in validators:
gt=0 will be applied to []
[]string will be spared validation
required will be applied to string
NOTE: in Example2 if the required validation failed, but all others passed
the hierarchy of FieldError's in the middle with have their IsPlaceHolder field
set to true. If a FieldError has IsSliceOrMap=true or IsMap=true then the
FieldError is a Slice or Map field and if IsPlaceHolder=true then contains errors
within its SliceOrArrayErrs or MapErrs fields.

required
This validates that the value is not the data types default value.
Expand Down