Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: benchmark decoder #227

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions decoder/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
t.Fatal(err)
}
if diff := cmp.Diff(expected, actual, exportAll); diff != "" {
t.Errorf(diff)

Check failure on line 96 in decoder/decode_test.go

View workflow job for this annotation

GitHub Actions / Lint

printf: non-constant format string in call to (*testing.common).Errorf (govet)
}
})

Expand All @@ -108,7 +108,7 @@
t.Fatal(err)
}
if diff := cmp.Diff(expected, actual, exportAll); diff != "" {
t.Errorf(diff)

Check failure on line 111 in decoder/decode_test.go

View workflow job for this annotation

GitHub Actions / Lint

printf: non-constant format string in call to (*testing.common).Errorf (govet)
}

actual = &test{}
Expand Down Expand Up @@ -239,3 +239,57 @@
}
})
}

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)
}
}
}
Loading