Skip to content

Commit

Permalink
Benchmarks for applying QueryParams in parseRequestURL function
Browse files Browse the repository at this point in the history
```shell
% go test -benchmem -bench=. -run=^Benchmark
goos: darwin
goarch: amd64
pkg: github.com/go-resty/resty/v2
cpu: Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Benchmark_parseRequestURL_QueryParam-16           663658              1806 ns/op             496 B/op         15 allocs/op
PASS
ok      github.com/go-resty/resty/v2    2.491s
```
  • Loading branch information
SVilgelm committed Sep 25, 2023
1 parent e9ef054 commit b7305a9
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,27 @@ func Benchmark_parseRequestURL_PathParams(b *testing.B) {
}
}
}

func Benchmark_parseRequestURL_QueryParams(b *testing.B) {
c := New().SetQueryParams(map[string]string{
"foo": "1",
"bar": "2",
}).SetQueryParams(map[string]string{
"foo": "3",
"xyz": "4",
})
r := c.R().SetQueryParams(map[string]string{
"foo": "5",
"qwe": "6",
}).SetQueryParams(map[string]string{
"foo": "7",
"asd": "8",
})
b.ResetTimer()
for i := 0; i < b.N; i++ {
r.URL = "https://example.com/"
if err := parseRequestURL(c, r); err != nil {
b.Errorf("parseRequestURL() error = %v", err)
}
}
}

0 comments on commit b7305a9

Please sign in to comment.