forked from monoculum/formam-benchmark
/
formam_2_test.go
104 lines (97 loc) · 2.38 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
package formam_benchmark
import (
"encoding/json"
"github.com/ajg/form"
"github.com/gorilla/schema"
"github.com/monoculum/formam"
"net/url"
"testing"
)
type BenchFormamSchema 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"},
}
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 BenchmarkAJGFormTest2(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
ne := new(BenchFormamSchema)
if err := form.DecodeValues(ne, valAJGT2); err != nil {
b.Error(err)
}
}
}
func BenchmarkSchemaTest2(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
ne := new(BenchFormamSchema)
dec := schema.NewDecoder()
if err := dec.Decode(ne, valSchemaT2); err != nil {
b.Error(err)
}
}
}
func BenchmarkFormamTest2(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
test := new(BenchFormamSchema)
if err := formam.Decode(valFormamT2, test); err != nil {
b.Error(err)
}
}
}
func BenchmarkJSONTest2(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
test := new(BenchFormamSchema)
if err := json.Unmarshal([]byte(valuesJSONT2), test); err != nil {
b.Error(err)
}
}
}