diff --git a/decoder/decode_test.go b/decoder/decode_test.go index 0d90378..b23ed21 100644 --- a/decoder/decode_test.go +++ b/decoder/decode_test.go @@ -239,3 +239,57 @@ func TestDecodeError(t *testing.T) { } }) } + +func BenchmarkDecoder(b *testing.B) { + type child struct { + String string `schema:"string"` + } + + type test struct { + String string `schema:"string"` + StringPtr *string `schema:"string"` + Int int `schema:"int"` + Int8 int8 `schema:"int8"` + Int16 int16 `schema:"int16"` + Int32 int32 `schema:"int32"` + Int64 int64 `schema:"int64"` + Uint uint `schema:"uint"` + Uint8 uint8 `schema:"uint8"` + Uint16 uint16 `schema:"uint16"` + Uint32 uint32 `schema:"uint32"` + Uint64 uint64 `schema:"uint64"` + Float32 float32 `schema:"float32"` + Float64 float64 `schema:"float64"` + Bool bool `schema:"bool"` + Strings []string `schema:"strings"` + Nested child + NestedPtr *child + } + + in := map[string][]string{ + "string": {"string"}, + "strings": {"string", "string"}, + "int": {"1"}, + "int8": {"1"}, + "int16": {"1"}, + "int32": {"1"}, + "int64": {"1"}, + "uint": {"1"}, + "uint8": {"1"}, + "uint16": {"1"}, + "uint32": {"1"}, + "uint64": {"1"}, + "float32": {"1"}, + "float64": {"1"}, + "bool": {"true"}, + } + + dec := decoder.New("schema") + + for i := 0; i < b.N; i++ { + out := &test{} + if err := dec.Decode(decoder.Map(in), out); err != nil { + b.Fatal(err) + } + } +}