-
Notifications
You must be signed in to change notification settings - Fork 718
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
Add Benchmarks and Unit tests for parseRequestBody and improve it #714
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #714 +/- ##
==========================================
+ Coverage 96.34% 96.57% +0.22%
==========================================
Files 12 12
Lines 1616 1607 -9
==========================================
- Hits 1557 1552 -5
+ Misses 37 35 -2
+ Partials 22 20 -2
☔ View full report in Codecov by Sentry. |
Tip: use benchstat. |
a950b1e
to
d702df2
Compare
This comment was marked as outdated.
This comment was marked as outdated.
thank you, didn't know |
Also, use something like |
This comment was marked as outdated.
This comment was marked as outdated.
```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_parseRequestBody_string-16 2194669 550.2 ns/op 128 B/op 3 allocs/op Benchmark_parseRequestBody_byte-16 2260675 531.5 ns/op 128 B/op 3 allocs/op Benchmark_parseRequestBody_reader_with_SetContentLength-16 8393974 141.4 ns/op 16 B/op 1 allocs/op Benchmark_parseRequestBody_reader_without_SetContentLength-16 14253069 84.30 ns/op 0 B/op 0 allocs/op Benchmark_parseRequestBody_struct-16 880549 1307 ns/op 155 B/op 5 allocs/op Benchmark_parseRequestBody_struct_xml-16 424707 2886 ns/op 4762 B/op 13 allocs/op Benchmark_parseRequestBody_map-16 547629 2152 ns/op 569 B/op 15 allocs/op Benchmark_parseRequestBody_slice-16 959576 1264 ns/op 146 B/op 4 allocs/op Benchmark_parseRequestBody_FormData-16 973964 1243 ns/op 304 B/op 14 allocs/op Benchmark_parseRequestBody_MultiPart-16 98246 12320 ns/op 8746 B/op 131 allocs/op ```
Benchmarks: ``` Old: Benchmark_parseRequestBody_FormData-16 954213 1266 ns/op 304 B/op 14 allocs/op New: Benchmark_parseRequestBody_FormData-16 968466 1248 ns/op 280 B/op 10 allocs/op ```
Benchmarks: ``` Old: Benchmark_parseRequestBody_string-16 2199196 550.3 ns/op 128 B/op 3 allocs/op Benchmark_parseRequestBody_byte-16 2264421 532.9 ns/op 128 B/op 3 allocs/op Benchmark_parseRequestBody_reader-16 8307141 141.8 ns/op 16 B/op 1 allocs/op Benchmark_parseRequestBody_struct-16 931632 1317 ns/op 156 B/op 5 allocs/op Benchmark_parseRequestBody_struct_xml-16 409074 2921 ns/op 4765 B/op 13 allocs/op Benchmark_parseRequestBody_map-16 566750 2158 ns/op 570 B/op 15 allocs/op Benchmark_parseRequestBody_slice-16 957828 1279 ns/op 146 B/op 4 allocs/op New: Benchmark_parseRequestBody_string-16 5084247 237.0 ns/op 16 B/op 1 allocs/op Benchmark_parseRequestBody_byte-16 5298362 218.0 ns/op 16 B/op 1 allocs/op Benchmark_parseRequestBody_reader-16 8402954 141.3 ns/op 16 B/op 1 allocs/op Benchmark_parseRequestBody_struct-16 1000000 1066 ns/op 42 B/op 3 allocs/op Benchmark_parseRequestBody_struct_xml-16 452389 2575 ns/op 4648 B/op 11 allocs/op Benchmark_parseRequestBody_map-16 620391 1913 ns/op 457 B/op 13 allocs/op Benchmark_parseRequestBody_slice-16 1207551 1203 ns/op 32 B/op 2 allocs/op ```
Final benchmarks: ```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_parseRequestBody_string-16 7623501 155.3 ns/op 16 B/op 1 allocs/op Benchmark_parseRequestBody_byte-16 8421992 141.6 ns/op 16 B/op 1 allocs/op Benchmark_parseRequestBody_reader_with_SetContentLength-16 17632350 67.37 ns/op 16 B/op 1 allocs/op Benchmark_parseRequestBody_reader_without_SetContentLength-16 26575016 45.34 ns/op 0 B/op 0 allocs/op Benchmark_parseRequestBody_struct-16 1243986 953.8 ns/op 40 B/op 2 allocs/op Benchmark_parseRequestBody_struct_xml-16 495250 2458 ns/op 4647 B/op 10 allocs/op Benchmark_parseRequestBody_map-16 694786 1761 ns/op 454 B/op 12 allocs/op Benchmark_parseRequestBody_slice-16 1304724 913.1 ns/op 32 B/op 2 allocs/op Benchmark_parseRequestBody_FormData-16 1000000 1128 ns/op 272 B/op 9 allocs/op Benchmark_parseRequestBody_MultiPart-16 93248 12583 ns/op 8738 B/op 130 allocs/op ```
New benchmarks, also no significant changes:
|
3ac1d58
to
3dc92da
Compare
3dc92da
to
3408a15
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SVilgelm Thank you!
Improve the
parseRequestBody
function and all nested functions.Original benchmarks:
% 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_parseRequestBody_string-16 2199196 550.3 ns/op 128 B/op 3 allocs/op Benchmark_parseRequestBody_byte-16 2264421 532.9 ns/op 128 B/op 3 allocs/op Benchmark_parseRequestBody_reader-16 8307141 141.8 ns/op 16 B/op 1 allocs/op Benchmark_parseRequestBody_struct-16 931632 1317 ns/op 156 B/op 5 allocs/op Benchmark_parseRequestBody_struct_xml-16 409074 2921 ns/op 4765 B/op 13 allocs/op Benchmark_parseRequestBody_map-16 566750 2158 ns/op 570 B/op 15 allocs/op Benchmark_parseRequestBody_slice-16 957828 1279 ns/op 146 B/op 4 allocs/op Benchmark_parseRequestBody_FormData-16 954213 1266 ns/op 304 B/op 14 allocs/op Benchmark_parseRequestBody_MultiPart-16 94276 12538 ns/op 8746 B/op 131 allocs/op
After the improvements: