- Use strings.Builder which minimizes allocations. - Avoid fmt.Sprintf which is slower than simple string concat. Results: name old time/op new time/op delta MapStringsToQueryParams/one_item-8 512ns ± 2% 377ns ± 1% -26.27% (p=0.000 n=10+9) MapStringsToQueryParams/multiple_items-8 858ns ± 5% 748ns ± 2% -12.82% (p=0.000 n=10+9) name old alloc/op new alloc/op delta MapStringsToQueryParams/one_item-8 456B ± 0% 384B ± 0% -15.79% (p=0.000 n=10+9) MapStringsToQueryParams/multiple_items-8 608B ± 0% 592B ± 0% -2.63% (p=0.000 n=10+10) name old allocs/op new allocs/op delta MapStringsToQueryParams/one_item-8 8.00 ± 0% 6.00 ± 0% -25.00% (p=0.000 n=10+10) MapStringsToQueryParams/multiple_items-8 12.0 ± 0% 12.0 ± 0% ~ (all equal)
1.4 KiB
1.4 KiB