Skip to content

Commit cbd857f

Browse files
joeybloggsjoeybloggs
authored andcommitted
add ajg benchmarks as someone requested a comparrison
1 parent 16f5e63 commit cbd857f

File tree

6 files changed

+379
-77
lines changed

6 files changed

+379
-77
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package form
22
============
33
<img align="right" src="https://raw.githubusercontent.com/go-playground/form/master/logo.jpg">
4-
![Project status](https://img.shields.io/badge/version-1.5.0-green.svg)
4+
![Project status](https://img.shields.io/badge/version-1.6.0-green.svg)
55
[![Build Status](https://semaphoreci.com/api/v1/joeybloggs/form/branches/master/badge.svg)](https://semaphoreci.com/joeybloggs/form)
66
[![Coverage Status](https://coveralls.io/repos/github/go-playground/form/badge.svg?branch=master)](https://coveralls.io/github/go-playground/form?branch=master)
77
[![Go Report Card](https://goreportcard.com/badge/github.com/go-playground/form)](https://goreportcard.com/report/github.com/go-playground/form)

benchmarks/ajg_form_test.go

Lines changed: 305 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,305 @@
1+
package benchmarks
2+
3+
import (
4+
"net/url"
5+
"testing"
6+
7+
ajg "github.com/ajg/form"
8+
)
9+
10+
// Simple Benchmarks
11+
12+
func BenchmarkSimpleUserDecodeStructAGJForm(b *testing.B) {
13+
14+
values := getUserStructValues()
15+
16+
b.ReportAllocs()
17+
for n := 0; n < b.N; n++ {
18+
var test User
19+
if err := ajg.DecodeValues(&test, values); err != nil {
20+
b.Error(err)
21+
}
22+
}
23+
}
24+
25+
func BenchmarkSimpleUserDecodeStructParallelAGJFrom(b *testing.B) {
26+
27+
values := getUserStructValues()
28+
29+
b.ReportAllocs()
30+
b.RunParallel(func(pb *testing.PB) {
31+
for pb.Next() {
32+
var test User
33+
if err := ajg.DecodeValues(&test, values); err != nil {
34+
b.Error(err)
35+
}
36+
}
37+
})
38+
}
39+
40+
func BenchmarkSimpleUserEncodeStructAGJForm(b *testing.B) {
41+
42+
test := getUserStruct()
43+
44+
b.ReportAllocs()
45+
for n := 0; n < b.N; n++ {
46+
if _, err := ajg.EncodeToValues(&test); err != nil {
47+
b.Error(err)
48+
}
49+
}
50+
}
51+
52+
func BenchmarkSimpleUserEncodeStructParallelAGJForm(b *testing.B) {
53+
54+
test := getUserStruct()
55+
56+
b.ReportAllocs()
57+
b.RunParallel(func(pb *testing.PB) {
58+
for pb.Next() {
59+
if _, err := ajg.EncodeToValues(&test); err != nil {
60+
b.Error(err)
61+
}
62+
}
63+
})
64+
}
65+
66+
// Primitives ALL types
67+
68+
func BenchmarkPrimitivesDecodeStructAllPrimitivesTypesAGJForm(b *testing.B) {
69+
values := getPrimitivesStructValues()
70+
71+
b.ReportAllocs()
72+
for n := 0; n < b.N; n++ {
73+
var test PrimitivesStruct
74+
if err := ajg.DecodeValues(&test, values); err != nil {
75+
b.Error(err)
76+
}
77+
}
78+
}
79+
80+
func BenchmarkPrimitivesDecodeStructAllPrimitivesTypesParallelAGJForm(b *testing.B) {
81+
values := getPrimitivesStructValues()
82+
83+
b.ReportAllocs()
84+
b.RunParallel(func(pb *testing.PB) {
85+
for pb.Next() {
86+
var test PrimitivesStruct
87+
if err := ajg.DecodeValues(&test, values); err != nil {
88+
b.Error(err)
89+
}
90+
}
91+
})
92+
}
93+
94+
func BenchmarkPrimitivesEncodeStructAllPrimitivesTypesAGJForm(b *testing.B) {
95+
test := getPrimitivesStruct()
96+
97+
b.ReportAllocs()
98+
for n := 0; n < b.N; n++ {
99+
if _, err := ajg.EncodeToValues(&test); err != nil {
100+
b.Error(err)
101+
}
102+
}
103+
}
104+
105+
func BenchmarkPrimitivesEncodeStructAllPrimitivesTypesParallelAGJForm(b *testing.B) {
106+
test := getPrimitivesStruct()
107+
108+
b.ReportAllocs()
109+
b.RunParallel(func(pb *testing.PB) {
110+
for pb.Next() {
111+
if _, err := ajg.EncodeToValues(&test); err != nil {
112+
b.Error(err)
113+
}
114+
}
115+
})
116+
}
117+
118+
// Complex Array ALL types
119+
120+
func BenchmarkComplexArrayDecodeStructAllTypesAGJForm(b *testing.B) {
121+
values := getComplexArrayStructValues()
122+
123+
b.ReportAllocs()
124+
for n := 0; n < b.N; n++ {
125+
var test ComplexArrayStruct
126+
if err := ajg.DecodeValues(&test, values); err != nil {
127+
b.Error(err)
128+
}
129+
}
130+
}
131+
132+
func BenchmarkComplexArrayDecodeStructAllTypesParallelAGJForm(b *testing.B) {
133+
values := getComplexArrayStructValues()
134+
135+
b.ReportAllocs()
136+
b.RunParallel(func(pb *testing.PB) {
137+
for pb.Next() {
138+
var test ComplexArrayStruct
139+
if err := ajg.DecodeValues(&test, values); err != nil {
140+
b.Error(err)
141+
}
142+
}
143+
})
144+
}
145+
146+
func BenchmarkComplexArrayEncodeStructAllTypesAGJForm(b *testing.B) {
147+
test := getComplexArrayStruct()
148+
149+
b.ReportAllocs()
150+
for n := 0; n < b.N; n++ {
151+
if _, err := ajg.EncodeToValues(&test); err != nil {
152+
b.Error(err)
153+
}
154+
}
155+
}
156+
157+
func BenchmarkComplexArrayEncodeStructAllTypesParallelAGJForm(b *testing.B) {
158+
test := getComplexArrayStruct()
159+
160+
b.ReportAllocs()
161+
b.RunParallel(func(pb *testing.PB) {
162+
for pb.Next() {
163+
if _, err := ajg.EncodeToValues(&test); err != nil {
164+
b.Error(err)
165+
}
166+
}
167+
})
168+
}
169+
170+
// Complex Map ALL types
171+
172+
func getComplexMapStructValuesAGJForm() url.Values {
173+
return url.Values{
174+
"String.key": []string{"value"},
175+
"StringPtr.key": []string{"value"},
176+
"Int.0": []string{"1"},
177+
"IntPtr.0": []string{"1"},
178+
"Int8.0": []string{"1"},
179+
"Int8Ptr.0": []string{"1"},
180+
"Int16.0": []string{"1"},
181+
"Int16Ptr.0": []string{"1"},
182+
"Int32.0": []string{"1"},
183+
"Int32Ptr.0": []string{"1"},
184+
"Int64.0": []string{"1"},
185+
"Int64Ptr.0": []string{"1"},
186+
"Uint.0": []string{"1"},
187+
"UintPtr.0": []string{"1"},
188+
"Uint8.0": []string{"1"},
189+
"Uint8Ptr.0": []string{"1"},
190+
"Uint16.0": []string{"1"},
191+
"Uint16Ptr.0": []string{"1"},
192+
"Uint32.0": []string{"1"},
193+
"Uint32Ptr.0": []string{"1"},
194+
"Uint64.0": []string{"1"},
195+
"Uint64Ptr.0": []string{"1"},
196+
"NestedInt.1.2": []string{"3"},
197+
"NestedIntPtr.1.2": []string{"3"},
198+
}
199+
}
200+
201+
func BenchmarkComplexMapDecodeStructAllTypesAGJForm(b *testing.B) {
202+
values := getComplexMapStructValuesAGJForm()
203+
204+
b.ReportAllocs()
205+
for n := 0; n < b.N; n++ {
206+
var test ComplexMapStruct
207+
if err := ajg.DecodeValues(&test, values); err != nil {
208+
b.Error(err)
209+
}
210+
}
211+
}
212+
213+
func BenchmarkComplexMapDecodeStructAllTypesParallelAGJForm(b *testing.B) {
214+
values := getComplexMapStructValuesAGJForm()
215+
216+
b.ReportAllocs()
217+
b.RunParallel(func(pb *testing.PB) {
218+
for pb.Next() {
219+
var test ComplexMapStruct
220+
if err := ajg.DecodeValues(&test, values); err != nil {
221+
b.Error(err)
222+
}
223+
}
224+
})
225+
}
226+
227+
func BenchmarkComplexMapEncodeStructAllTypesAGJForm(b *testing.B) {
228+
test := getComplexMapStructValuesAGJForm()
229+
230+
b.ReportAllocs()
231+
for n := 0; n < b.N; n++ {
232+
if _, err := ajg.EncodeToValues(&test); err != nil {
233+
b.Error(err)
234+
}
235+
}
236+
}
237+
238+
func BenchmarkComplexMapEncodeStructAllTypesParallelAGJForm(b *testing.B) {
239+
test := getComplexMapStructValuesAGJForm()
240+
241+
b.ReportAllocs()
242+
b.RunParallel(func(pb *testing.PB) {
243+
for pb.Next() {
244+
if _, err := ajg.EncodeToValues(&test); err != nil {
245+
b.Error(err)
246+
}
247+
}
248+
})
249+
}
250+
251+
// NestedStruct Benchmarks
252+
253+
func BenchmarkDecodeNestedStructAGJForm(b *testing.B) {
254+
255+
values := getNestedStructValues()
256+
257+
b.ReportAllocs()
258+
for n := 0; n < b.N; n++ {
259+
var test NestedStruct
260+
if err := ajg.DecodeValues(&test, values); err != nil {
261+
b.Error(err)
262+
}
263+
}
264+
}
265+
266+
func BenchmarkDecodeNestedStructParallelAGJForm(b *testing.B) {
267+
268+
values := getNestedStructValues()
269+
270+
b.ReportAllocs()
271+
b.RunParallel(func(pb *testing.PB) {
272+
for pb.Next() {
273+
var test NestedStruct
274+
if err := ajg.DecodeValues(&test, values); err != nil {
275+
b.Error(err)
276+
}
277+
}
278+
})
279+
}
280+
281+
func BenchmarkEncodeNestedStructAGJForm(b *testing.B) {
282+
283+
test := getNestedStruct()
284+
285+
b.ReportAllocs()
286+
for n := 0; n < b.N; n++ {
287+
if _, err := ajg.EncodeToValues(&test); err != nil {
288+
b.Error(err)
289+
}
290+
}
291+
}
292+
293+
func BenchmarkEncodeNestedStructParallelAGJForm(b *testing.B) {
294+
295+
test := getNestedStruct()
296+
297+
b.ReportAllocs()
298+
b.RunParallel(func(pb *testing.PB) {
299+
for pb.Next() {
300+
if _, err := ajg.EncodeToValues(&test); err != nil {
301+
b.Error(err)
302+
}
303+
}
304+
})
305+
}

benchmarks/benchmarks.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,32 @@ BenchmarkArrayMapNestedStructFormam-8 --- FAIL: Benchmark
6060
BenchmarkArrayMapNestedStructFormamParallel-8 --- FAIL: BenchmarkArrayMapNestedStructFormamParallel-8
6161
formam_test.go:189: formam: not supported type for field "Value" in path "NestedPtrArray[0].Value"
6262
No Encoder Support At This Time
63+
```
64+
65+
### ajg/form
66+
```go
67+
BenchmarkSimpleUserDecodeStructAGJForm-8 200000 6104 ns/op 1320 B/op 34 allocs/op
68+
BenchmarkSimpleUserDecodeStructParallelAGJFrom-8 1000000 1748 ns/op 1320 B/op 34 allocs/op
69+
BenchmarkSimpleUserEncodeStructAGJForm-8 300000 5076 ns/op 1272 B/op 29 allocs/op
70+
BenchmarkSimpleUserEncodeStructParallelAGJForm-8 1000000 1440 ns/op 1272 B/op 29 allocs/op
71+
BenchmarkPrimitivesDecodeStructAllPrimitivesTypesAGJForm-8 100000 19713 ns/op 5661 B/op 143 allocs/op
72+
BenchmarkPrimitivesDecodeStructAllPrimitivesTypesParallelAGJForm-8 300000 5618 ns/op 5663 B/op 143 allocs/op
73+
BenchmarkPrimitivesEncodeStructAllPrimitivesTypesAGJForm-8 100000 15097 ns/op 5792 B/op 82 allocs/op
74+
BenchmarkPrimitivesEncodeStructAllPrimitivesTypesParallelAGJForm-8 300000 4340 ns/op 5792 B/op 82 allocs/op
75+
BenchmarkComplexArrayDecodeStructAllTypesAGJForm-8 --- FAIL: BenchmarkComplexArrayDecodeStructAllTypesAGJForm-8
76+
agj_form_test.go:127: is not a valid index for type []uint16
77+
BenchmarkComplexArrayDecodeStructAllTypesParallelAGJForm-8 --- FAIL: BenchmarkComplexArrayDecodeStructAllTypesParallelAGJForm-8
78+
agj_form_test.go:140: is not a valid index for type []int32
79+
BenchmarkComplexArrayEncodeStructAllTypesAGJForm-8 20000 66822 ns/op 21684 B/op 400 allocs/op
80+
BenchmarkComplexArrayEncodeStructAllTypesParallelAGJForm-8 100000 20173 ns/op 21681 B/op 400 allocs/op
81+
BenchmarkComplexMapDecodeStructAllTypesAGJForm-8 20000 86037 ns/op 22295 B/op 592 allocs/op
82+
BenchmarkComplexMapDecodeStructAllTypesParallelAGJForm-8 50000 25491 ns/op 22297 B/op 592 allocs/op
83+
BenchmarkComplexMapEncodeStructAllTypesAGJForm-8 30000 44735 ns/op 17959 B/op 323 allocs/op
84+
BenchmarkComplexMapEncodeStructAllTypesParallelAGJForm-8 100000 13961 ns/op 17958 B/op 323 allocs/op
85+
BenchmarkDecodeNestedStructAGJForm-8 --- FAIL: BenchmarkDecodeNestedStructAGJForm-8
86+
agj_form_test.go:261: NestedArray[1] doesn't exist in benchmarks.NestedStruct
87+
BenchmarkDecodeNestedStructParallelAGJForm-8 --- FAIL: BenchmarkDecodeNestedStructParallelAGJForm-8
88+
agj_form_test.go:275: NestedArray[0] doesn't exist in benchmarks.NestedStruct
89+
BenchmarkEncodeNestedStructAGJForm-8 100000 17904 ns/op 5704 B/op 113 allocs/op
90+
BenchmarkEncodeNestedStructParallelAGJForm-8 300000 5502 ns/op 5704 B/op 113 allocs/op
6391
```

0 commit comments

Comments
 (0)