MCPcopy
hub / github.com/gin-gonic/gin / BenchmarkGetMapFromFormData

Function BenchmarkGetMapFromFormData

context_test.go:3700–3783  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

3698}
3699
3700func BenchmarkGetMapFromFormData(b *testing.B) {
3701 // Test case 1: Small dataset with bracket notation
3702 smallData := map[string][]string{
3703 "ids[a]": {"hi"},
3704 "ids[b]": {"3.14"},
3705 "names[a]": {"mike"},
3706 "names[b]": {"maria"},
3707 }
3708
3709 // Test case 2: Medium dataset with mixed data
3710 mediumData := map[string][]string{
3711 "ids[a]": {"hi"},
3712 "ids[b]": {"3.14"},
3713 "ids[c]": {"test"},
3714 "ids[d]": {"value"},
3715 "names[a]": {"mike"},
3716 "names[b]": {"maria"},
3717 "names[c]": {"john"},
3718 "names[d]": {"jane"},
3719 "other[key1]": {"value1"},
3720 "other[key2]": {"value2"},
3721 "simple": {"data"},
3722 "another": {"info"},
3723 }
3724
3725 // Test case 3: Large dataset with many bracket keys
3726 largeData := make(map[string][]string)
3727 for i := range 100 {
3728 key := fmt.Sprintf("ids[%d]", i)
3729 largeData[key] = []string{fmt.Sprintf("value%d", i)}
3730 }
3731 for i := range 50 {
3732 key := fmt.Sprintf("names[%d]", i)
3733 largeData[key] = []string{fmt.Sprintf("name%d", i)}
3734 }
3735 for i := range 25 {
3736 key := fmt.Sprintf("other[key%d]", i)
3737 largeData[key] = []string{fmt.Sprintf("other%d", i)}
3738 }
3739
3740 // Test case 4: Dataset with many non-matching keys (worst case)
3741 worstCaseData := make(map[string][]string)
3742 for i := range 100 {
3743 key := fmt.Sprintf("nonmatching%d", i)
3744 worstCaseData[key] = []string{fmt.Sprintf("value%d", i)}
3745 }
3746 worstCaseData["ids[a]"] = []string{"hi"}
3747 worstCaseData["ids[b]"] = []string{"3.14"}
3748
3749 // Test case 5: Dataset with short keys (best case for early exit)
3750 shortKeysData := map[string][]string{
3751 "a": {"value1"},
3752 "b": {"value2"},
3753 "ids[a]": {"hi"},
3754 "ids[b]": {"3.14"},
3755 }
3756
3757 benchmarks := []struct {

Callers

nothing calls this directly

Calls 2

getMapFromFormDataFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…