-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathformam_1_test.go
128 lines (119 loc) · 3.03 KB
/
formam_1_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package formam_benchmark
import (
"encoding/json"
"net/url"
"testing"
"github.com/ajg/form"
formm "github.com/go-playground/form"
"github.com/gorilla/schema"
"github.com/monoculum/formam"
)
type Simple struct {
Nest struct {
Children []struct {
ID string
Name string
}
}
String string
Slice []int
Bool bool
}
var (
valFormamT2 = url.Values{
"Nest.Children[0].ID": []string{"monoculum_id"},
"Nest.Children[0].Name": []string{"Monoculum"},
"String": []string{"golang is very fun"},
"Slice[0]": []string{"1"},
"Slice[1]": []string{"2"},
"Slice[2]": []string{"3"},
"Slice[3]": []string{"4"},
"Bool": []string{"true"},
}
valFormT2 = url.Values{
"Nest.Children[0].ID": []string{"monoculum_id"},
"Nest.Children[0].Name": []string{"Monoculum"},
"String": []string{"golang is very fun"},
"Slice[0]": []string{"1"},
"Slice[1]": []string{"2"},
"Slice[2]": []string{"3"},
"Slice[3]": []string{"4"},
"Bool": []string{"true"},
}
valSchemaT2 = url.Values{
"Nest.Children.0.ID": []string{"monoculum_id"},
"Nest.Children.0.Name": []string{"Monoculum"},
"String": []string{"golang is very fun"},
"Slice": []string{"1", "2", "3", "4"},
"Bool": []string{"true"},
}
valAJGT2 = url.Values{
"Nest.Children.0.ID": []string{"monoculum_id"},
"Nest.Children.0.Name": []string{"Monoculum"},
"String": []string{"golang is very fun"},
"Slice.0": []string{"1"},
"Slice.1": []string{"2"},
"Slice.2": []string{"3"},
"Slice.3": []string{"4"},
"Bool": []string{"true"},
}
valuesJSONT2 = `
{
"Nest":
{
"Children": [{"ID": "monoculum_id", "Name":"Monoculum"}]
},
"string": "golang is very fun",
"Slice": [1, 2, 3, 4],
"Bool": true
}
`
)
func BenchmarkAJGFormTestSIMPLE(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
ne := new(Simple)
if err := form.DecodeValues(ne, valAJGT2); err != nil {
b.Error(err)
}
}
}
func BenchmarkSchemaTestSIMPLE(b *testing.B) {
dec := schema.NewDecoder()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
ne := new(Simple)
if err := dec.Decode(ne, valSchemaT2); err != nil {
b.Error(err)
}
}
}
func BenchmarkFormamTestSIMPLE(b *testing.B) {
b.ReportAllocs()
dec := formam.NewDecoder(nil)
for i := 0; i < b.N; i++ {
test := new(Simple)
if err := dec.Decode(valFormamT2, test); err != nil {
b.Error(err)
}
}
}
func BenchmarkFormTestSIMPLE(b *testing.B) {
decoder := formm.NewDecoder()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
test := new(Simple)
if err := decoder.Decode(test, valFormT2); err != nil {
b.Error(err)
}
}
}
func BenchmarkJSONTestSIMPLE(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
test := new(Simple)
if err := json.Unmarshal([]byte(valuesJSONT2), test); err != nil {
b.Error(err)
}
}
}