Skip to content

Commit aea44d1

Browse files
joeybloggsjoeybloggs
authored andcommitted
Add competitor benchmarks
- corrected a couple of benchmarks with typos.
1 parent df22d51 commit aea44d1

File tree

6 files changed

+455
-23
lines changed

6 files changed

+455
-23
lines changed

README.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ decoder.RegisterCustomTypeFunc(func(vals []string) (interface{}, error) {
152152
}, time.Time{})
153153
```
154154

155+
Ignoring Fields
156+
--------------
157+
you can tell form to ignore fields using `-` in the tag
158+
```go
159+
type MyStruct struct {
160+
Field string `form:"-"`
161+
}
162+
```
163+
155164
Benchmarks
156165
------
157166
###### Run on MacBook Pro (Retina, 15-inch, Late 2013) 2.6 GHz Intel Core i7 16 GB 1600 MHz DDR3 using Go version go1.6.2 darwin/amd64
@@ -162,18 +171,19 @@ NOTE: the 1 allocation and B/op in the first 4 is actually the struct allocating
162171
go test -bench=. -benchmem=true
163172

164173
PASS
165-
BenchmarkSimpleUserStruct-8 5000000 320 ns/op 64 B/op 1 allocs/op
166-
BenchmarkSimpleUserStructParallel-8 20000000 110 ns/op 64 B/op 1 allocs/op
167-
BenchmarkPrimitivesStructAllPrimitivesTypes-8 1000000 1075 ns/op 96 B/op 1 allocs/op
168-
BenchmarkPrimitivesStructAllPrimitivesTypesParallel-8 5000000 285 ns/op 96 B/op 1 allocs/op
169-
BenchmarkComplexArrayStructAllTypes-8 100000 19748 ns/op 6600 B/op 143 allocs/op
170-
BenchmarkComplexArrayStructAllTypesParallel-8 300000 5844 ns/op 6600 B/op 143 allocs/op
171-
BenchmarkComplexMapStructAllTypes-8 50000 33943 ns/op 20276 B/op 224 allocs/op
172-
BenchmarkComplexMapStructAllTypesParallel-8 200000 12228 ns/op 20277 B/op 224 allocs/op
173-
BenchmarkArrayMapNestedStruct-8 300000 4658 ns/op 1840 B/op 27 allocs/op
174-
BenchmarkArrayMapNestedStructParallel-8 1000000 1498 ns/op 1840 B/op 27 allocs/op
174+
BenchmarkSimpleUserStruct-8 5000000 299 ns/op 64 B/op 1 allocs/op
175+
BenchmarkSimpleUserStructParallel-8 20000000 110 ns/op 64 B/op 1 allocs/op
176+
BenchmarkPrimitivesStructAllPrimitivesTypes-8 2000000 956 ns/op 96 B/op 1 allocs/op
177+
BenchmarkPrimitivesStructAllPrimitivesTypesParallel-8 5000000 285 ns/op 96 B/op 1 allocs/op
178+
BenchmarkComplexArrayStructAllTypes-8 100000 20706 ns/op 6776 B/op 159 allocs/op
179+
BenchmarkComplexArrayStructAllTypesParallel-8 200000 6158 ns/op 6776 B/op 159 allocs/op
180+
BenchmarkComplexMapStructAllTypes-8 50000 35548 ns/op 20966 B/op 245 allocs/op
181+
BenchmarkComplexMapStructAllTypesParallel-8 200000 11984 ns/op 20966 B/op 245 allocs/op
182+
BenchmarkArrayMapNestedStruct-8 200000 5617 ns/op 2064 B/op 37 allocs/op
183+
BenchmarkArrayMapNestedStructParallel-8 1000000 2032 ns/op 2064 B/op 37 allocs/op
175184
```
176185

186+
Competitor benchmarks can be found [here](https://github.com/go-playground/form/blob/master/benchmarks/benchmarks.md)
177187

178188
Complimentary Software
179189
----------------------

benchmarks/benchmarks.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## Benchmarks
2+
3+
### go-playground/form
4+
BenchmarkSimpleUserStruct-8 5000000 299 ns/op 64 B/op 1 allocs/op
5+
BenchmarkSimpleUserStructParallel-8 20000000 110 ns/op 64 B/op 1 allocs/op
6+
BenchmarkPrimitivesStructAllPrimitivesTypes-8 2000000 956 ns/op 96 B/op 1 allocs/op
7+
BenchmarkPrimitivesStructAllPrimitivesTypesParallel-8 5000000 285 ns/op 96 B/op 1 allocs/op
8+
BenchmarkComplexArrayStructAllTypes-8 100000 20706 ns/op 6776 B/op 159 allocs/op
9+
BenchmarkComplexArrayStructAllTypesParallel-8 200000 6158 ns/op 6776 B/op 159 allocs/op
10+
BenchmarkComplexMapStructAllTypes-8 50000 35548 ns/op 20966 B/op 245 allocs/op
11+
BenchmarkComplexMapStructAllTypesParallel-8 200000 11984 ns/op 20966 B/op 245 allocs/op
12+
BenchmarkArrayMapNestedStruct-8 200000 5617 ns/op 2064 B/op 37 allocs/op
13+
BenchmarkArrayMapNestedStructParallel-8 1000000 2032 ns/op 2064 B/op 37 allocs/op
14+
15+
### gorilla/schema
16+
BenchmarkSimpleUserStructGorilla-8 500000 3063 ns/op 520 B/op 23 allocs/op
17+
BenchmarkSimpleUserStructGorillaParallel-8 1000000 1026 ns/op 520 B/op 23 allocs/op
18+
BenchmarkPrimitivesStructAllPrimitivesTypesGorilla-8 200000 11136 ns/op 1536 B/op 84 allocs/op
19+
BenchmarkPrimitivesStructAllPrimitivesTypesGorillaParallel-8 500000 3928 ns/op 1536 B/op 84 allocs/op
20+
BenchmarkComplexArrayStructAllTypesGorilla-8 50000 34162 ns/op 5416 B/op 223 allocs/op
21+
BenchmarkComplexArrayStructAllTypesGorillaParallel-8 200000 11937 ns/op 5416 B/op 223 allocs/op
22+
BenchmarkComplexMapStructAllTypesGorilla-8 0 0 ns/op 0 B/op 0 allocs/op
23+
--- BENCH: BenchmarkComplexMapStructAllTypesGorilla-8
24+
gorilla_scheme_test.go:116: Gorilla does not support map parsing at this time
25+
BenchmarkComplexMapStructAllTypesGorillaParallel-8 0 0 ns/op 0 B/op 0 allocs/op
26+
--- BENCH: BenchmarkComplexMapStructAllTypesGorillaParallel-8
27+
gorilla_scheme_test.go:121: Gorilla does not support map parsing at this time
28+
BenchmarkArrayMapNestedStructGorilla-8 200000 10393 ns/op 2269 B/op 73 allocs/op
29+
BenchmarkArrayMapNestedStructGorillaParallel-8 500000 3484 ns/op 2269 B/op 73 allocs/op
30+
31+
### monoculum/formam
32+
BenchmarkSimpleUserStructFormam-8 500000 3713 ns/op 264 B/op 19 allocs/op
33+
BenchmarkSimpleUserStructFormamParallel-8 1000000 1017 ns/op 264 B/op 19 allocs/op
34+
BenchmarkPrimitivesStructAllPrimitivesFormamTypes-8 100000 12197 ns/op 1280 B/op 134 allocs/op
35+
BenchmarkPrimitivesStructAllPrimitivesTypesFormamParallel-8 500000 3905 ns/op 1280 B/op 134 allocs/op
36+
BenchmarkComplexArrayStructAllTypesFormam-8 30000 58650 ns/op 6371 B/op 522 allocs/op
37+
BenchmarkComplexArrayStructAllTypesFormamParallel-8 100000 19046 ns/op 6349 B/op 521 allocs/op
38+
BenchmarkComplexMapStructAllTypesFormam-8 --- FAIL: BenchmarkComplexMapStructAllTypesFormam-8
39+
formam_test.go:142: formam: the key with uint16 type (map[uint16]uint16) in the path Uint16.0 should implements the TextUnmarshaler interface for to can decode it
40+
BenchmarkComplexMapStructAllTypesFormamParallel-8 --- FAIL: BenchmarkComplexMapStructAllTypesFormamParallel-8
41+
formam_test.go:158: formam: the key with int type (map[int]int) in the path Int.0 should implements the TextUnmarshaler interface for to can decode it
42+
BenchmarkArrayMapNestedStructFormam-8 --- FAIL: BenchmarkArrayMapNestedStructFormam-8
43+
formam_test.go:174: formam: not supported type for field "Value" in path "NestedPtrArray[1].Value"
44+
BenchmarkArrayMapNestedStructFormamParallel-8 --- FAIL: BenchmarkArrayMapNestedStructFormamParallel-8
45+
formam_test.go:189: formam: not supported type for field "Value" in path "NestedPtrArray[0].Value"

benchmarks/benchmarks_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import (
1010
// Simple Benchmarks
1111

1212
type User struct {
13-
FirstName string `form:"fname"`
14-
LastName string `form:"lname"`
15-
Email string `form:"email"`
16-
Age uint8 `form:"age"`
13+
FirstName string `form:"fname" schema:"fname" formam:"fname"`
14+
LastName string `form:"lname" schema:"lname" formam:"lname"`
15+
Email string `form:"email" schema:"email" formam:"email"`
16+
Age uint8 `form:"age" schema:"age" formam:"age"`
1717
}
1818

1919
func getUserStructValues() url.Values {
@@ -90,7 +90,7 @@ func getPrimitivesStructValues() url.Values {
9090
"Uint64": []string{"5"},
9191
"Float32": []string{"1.1"},
9292
"Float64": []string{"5.0"},
93-
"Bool": []string{"t"},
93+
"Bool": []string{"true"},
9494
}
9595
}
9696

@@ -144,9 +144,9 @@ type ComplexArrayStruct struct {
144144
Uint8 []uint8
145145
Uint8Ptr []*uint8
146146
Uint16 []uint16
147-
UInt16Ptr []*uint16
148-
UInt32 []uint32
149-
Uint31Ptr []*uint32
147+
Uint16Ptr []*uint16
148+
Uint32 []uint32
149+
Uint32Ptr []*uint32
150150
Uint64 []uint64
151151
Uint64Ptr []*uint64
152152
NestedInt [][]int
@@ -236,9 +236,9 @@ type ComplexMapStruct struct {
236236
Uint8 map[uint8]uint8
237237
Uint8Ptr map[*uint8]*uint8
238238
Uint16 map[uint16]uint16
239-
UInt16Ptr map[*uint16]*uint16
240-
UInt32 map[*uint32]*uint32
241-
Uint31Ptr map[*uint32]*uint32
239+
Uint16Ptr map[*uint16]*uint16
240+
Uint32 map[*uint32]*uint32
241+
Uint32Ptr map[*uint32]*uint32
242242
Uint64 map[*uint64]*uint64
243243
Uint64Ptr map[*uint64]*uint64
244244
NestedInt map[int]map[int]int
@@ -330,8 +330,8 @@ func getNestedStructValues() url.Values {
330330
"NestedArray[0].Value": []string{"value"},
331331
"NestedArray[1].Value": []string{"value"},
332332
// Nested Array Ptr
333-
"NestedArrayPtr[0].Value": []string{"value"},
334-
"NestedArrayPtr[1].Value": []string{"value"},
333+
"NestedPtrArray[0].Value": []string{"value"},
334+
"NestedPtrArray[1].Value": []string{"value"},
335335
// Nested 2
336336
"Nested2.Value": []string{"value"},
337337
"Nested2.Nested2.Value": []string{"value"},

benchmarks/formam_test.go

Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
1+
package benchmarks
2+
3+
import (
4+
"net/url"
5+
"testing"
6+
7+
"github.com/monoculum/formam"
8+
)
9+
10+
// Simple Benchmarks
11+
12+
func BenchmarkSimpleUserStructFormam(b *testing.B) {
13+
14+
values := getUserStructValues()
15+
var err error
16+
b.ReportAllocs()
17+
for n := 0; n < b.N; n++ {
18+
var test User
19+
if err = formam.Decode(values, &test); err != nil {
20+
b.Error(err)
21+
}
22+
}
23+
}
24+
25+
func BenchmarkSimpleUserStructFormamParallel(b *testing.B) {
26+
27+
values := getUserStructValues()
28+
var err error
29+
30+
b.ReportAllocs()
31+
b.RunParallel(func(pb *testing.PB) {
32+
for pb.Next() {
33+
var test User
34+
if err = formam.Decode(values, &test); err != nil {
35+
b.Error(err)
36+
}
37+
}
38+
})
39+
}
40+
41+
// Primitives ALL types
42+
43+
func BenchmarkPrimitivesStructAllPrimitivesFormamTypes(b *testing.B) {
44+
values := getPrimitivesStructValues()
45+
var err error
46+
47+
b.ReportAllocs()
48+
for n := 0; n < b.N; n++ {
49+
var test PrimitivesStruct
50+
if err = formam.Decode(values, &test); err != nil {
51+
b.Error(err)
52+
}
53+
}
54+
}
55+
56+
func BenchmarkPrimitivesStructAllPrimitivesTypesFormamParallel(b *testing.B) {
57+
values := getPrimitivesStructValues()
58+
var err error
59+
60+
b.ReportAllocs()
61+
b.RunParallel(func(pb *testing.PB) {
62+
for pb.Next() {
63+
var test PrimitivesStruct
64+
if err = formam.Decode(values, &test); err != nil {
65+
b.Error(err)
66+
}
67+
}
68+
})
69+
}
70+
71+
// Complex Array ALL types
72+
73+
func BenchmarkComplexArrayStructAllTypesFormam(b *testing.B) {
74+
values := getComplexArrayStructValues()
75+
var err error
76+
77+
b.ReportAllocs()
78+
for n := 0; n < b.N; n++ {
79+
var test ComplexArrayStruct
80+
if err = formam.Decode(values, &test); err != nil {
81+
b.Error(err)
82+
}
83+
}
84+
}
85+
86+
func BenchmarkComplexArrayStructAllTypesFormamParallel(b *testing.B) {
87+
values := getComplexArrayStructValues()
88+
var err error
89+
90+
b.ReportAllocs()
91+
b.RunParallel(func(pb *testing.PB) {
92+
for pb.Next() {
93+
var test ComplexArrayStruct
94+
if err = formam.Decode(values, &test); err != nil {
95+
b.Error(err)
96+
}
97+
}
98+
})
99+
}
100+
101+
// Complex Map ALL types
102+
103+
func getComplexMapStructValuesFormam() url.Values {
104+
return url.Values{
105+
"String.key": []string{"value"},
106+
"StringPtr.key": []string{"value"},
107+
"Int.0": []string{"1"},
108+
"IntPtr.0": []string{"1"},
109+
"Int8.0": []string{"1"},
110+
"Int8Ptr.0": []string{"1"},
111+
"Int16.0": []string{"1"},
112+
"Int16Ptr.0": []string{"1"},
113+
"Int32.0": []string{"1"},
114+
"Int32Ptr.0": []string{"1"},
115+
"Int64.0": []string{"1"},
116+
"Int64Ptr.0": []string{"1"},
117+
"Uint.0": []string{"1"},
118+
"UintPtr.0": []string{"1"},
119+
"Uint8.0": []string{"1"},
120+
"Uint8Ptr.0": []string{"1"},
121+
"Uint16.0": []string{"1"},
122+
"Uint16Ptr.0": []string{"1"},
123+
"Uint32.0": []string{"1"},
124+
"Uint32Ptr.0": []string{"1"},
125+
"Uint64.0": []string{"1"},
126+
"Uint64Ptr.0": []string{"1"},
127+
"NestedInt.1.2": []string{"3"},
128+
"NestedIntPtr.1.2": []string{"3"},
129+
}
130+
}
131+
132+
func BenchmarkComplexMapStructAllTypesFormam(b *testing.B) {
133+
// b.Log("Formam only supports map key of string at this time")
134+
// b.SkipNow()
135+
values := getComplexMapStructValuesFormam()
136+
var err error
137+
138+
b.ReportAllocs()
139+
for n := 0; n < b.N; n++ {
140+
var test ComplexMapStruct
141+
if err = formam.Decode(values, &test); err != nil {
142+
b.Error(err)
143+
}
144+
}
145+
}
146+
147+
func BenchmarkComplexMapStructAllTypesFormamParallel(b *testing.B) {
148+
// b.Log("Formam only supports map key of string at this time")
149+
// b.SkipNow()
150+
values := getComplexMapStructValuesFormam()
151+
var err error
152+
153+
b.ReportAllocs()
154+
b.RunParallel(func(pb *testing.PB) {
155+
for pb.Next() {
156+
var test ComplexMapStruct
157+
if err = formam.Decode(values, &test); err != nil {
158+
b.Error(err)
159+
}
160+
}
161+
})
162+
}
163+
164+
// NestedStruct Benchmarks
165+
166+
func BenchmarkArrayMapNestedStructFormam(b *testing.B) {
167+
168+
values := getNestedStructValues()
169+
var err error
170+
b.ReportAllocs()
171+
for n := 0; n < b.N; n++ {
172+
var test NestedStruct
173+
if err = formam.Decode(values, &test); err != nil {
174+
b.Error(err)
175+
}
176+
}
177+
}
178+
179+
func BenchmarkArrayMapNestedStructFormamParallel(b *testing.B) {
180+
181+
values := getNestedStructValues()
182+
var err error
183+
184+
b.ReportAllocs()
185+
b.RunParallel(func(pb *testing.PB) {
186+
for pb.Next() {
187+
var test NestedStruct
188+
if err = formam.Decode(values, &test); err != nil {
189+
b.Error(err)
190+
}
191+
}
192+
})
193+
}

0 commit comments

Comments
 (0)