-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathformam_2_test.go
130 lines (121 loc) · 3.52 KB
/
formam_2_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
129
130
package formam_benchmark
import (
"encoding/json"
"net/url"
"testing"
"github.com/ajg/form"
formm "github.com/go-playground/form"
"github.com/monoculum/formam"
)
type Anonymous struct {
Int int `form:"int" formam:"int" json:"int"`
}
type Medium struct {
Nest struct {
Children []struct {
ID string
Name string
}
}
String string `form:"string" formam:"string" json:"string"`
Slice []int
Map map[string][]string
Bool bool
Anonymous
//Int int `form:"int" formam:"int" json:"int"`
}
var (
valuesFormamT1 = url.Values{
"Nest.Children[0].ID": []string{"monoculum_id"},
"Nest.Children[0].Name": []string{"Monoculum"},
"Map[es_Es][0]": []string{"javier"},
"Map[es_Es][1]": []string{"javier"},
"Map[es_Es][2]": []string{"javier"},
"Map[es_Es][3]": []string{"javier"},
"Map[es_Es][4]": []string{"javier"},
"Map[es_Es][5]": []string{"javier"},
"string": []string{"golang is very fun"},
"Slice[0]": []string{"1"},
"Slice[1]": []string{"2"},
"int": []string{"1"},
"Bool": []string{"true"},
}
valuesFormT1 = url.Values{
"Nest.Children[0].ID": []string{"monoculum_id"},
"Nest.Children[0].Name": []string{"Monoculum"},
"Map[es_Es][0]": []string{"javier"},
"Map[es_Es][1]": []string{"javier"},
"Map[es_Es][2]": []string{"javier"},
"Map[es_Es][3]": []string{"javier"},
"Map[es_Es][4]": []string{"javier"},
"Map[es_Es][5]": []string{"javier"},
"string": []string{"golang is very fun"},
"Slice[0]": []string{"1"},
"Slice[1]": []string{"2"},
"int": []string{"1"},
"Bool": []string{"true"},
}
valuesAJGFormT1 = url.Values{
"Nest.Children.0.ID": []string{"monoculum_id"},
"Nest.Children.0.Name": []string{"Monoculum"},
"Map.es_Es.0": []string{"javier"},
"Map.es_Es.1": []string{"javier"},
"Map.es_Es.2": []string{"javier"},
"Map.es_Es.3": []string{"javier"},
"Map.es_Es.4": []string{"javier"},
"Map.es_Es.5": []string{"javier"},
"string": []string{"golang is very fun"},
"Slice.0": []string{"1"},
"Slice.1": []string{"2"},
"int": []string{"1"},
"Bool": []string{"true"},
}
valuesJSONT1 = `
{
"Nest": {"Children": [{"ID": "monoculum_id", "Name":"Monoculum"}]},
"string": "golang is very fun",
"Map": {"es_Es": ["javier", "javier", "javier", "javier", "javier", "javier"]},
"Slice": [1, 2],
"int": 20,
"Bool": true
}
`
)
func BenchmarkAJGFormTestMEDIUM(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
ne := new(Medium)
if err := form.DecodeValues(ne, valuesAJGFormT1); err != nil {
b.Error(err)
}
}
}
func BenchmarkFormamTestMEDIUM(b *testing.B) {
deco := formam.NewDecoder(nil)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
test := new(Medium)
if err := deco.Decode(valuesFormamT1, test); err != nil {
b.Error(err)
}
}
}
func BenchmarkFormTestMEDIUM(b *testing.B) {
decoder := formm.NewDecoder()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
test := new(Medium)
if err := decoder.Decode(test, valuesFormT1); err != nil {
b.Error(err)
}
}
}
func BenchmarkJSONTestMEDIUM(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
test := new(Medium)
if err := json.Unmarshal([]byte(valuesJSONT1), test); err != nil {
b.Error(err)
}
}
}