refactor: use b.Loop() in benchmark tests for better performance #785
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
These changes use b.Loop() to simplify the code and improve performance
Supported by Go Team, more info: https://go.dev/blog/testing-b-loop and https://go.dev/issue/73137.
Before:
go test -run=^$ -bench=. ./pkg/tss goos: darwin goarch: arm64 pkg: github.com/bandprotocol/chain/v3/pkg/tss cpu: Apple M3 BenchmarkEncrypt-10 622239 1948 ns/op BenchmarkDecrypt-10 669828 1712 ns/op BenchmarkHash/1_byte-10 4624423 259.6 ns/op BenchmarkHash/4_bytes-10 4632673 261.5 ns/op BenchmarkHash/32_bytes-10 4561328 290.9 ns/op BenchmarkHash/128_bytes-10 3918991 269.3 ns/op BenchmarkHash/1024_bytes-10 654266 1896 ns/op BenchmarkHash/8096_bytes-10 85849 13515 ns/op BenchmarkSumScalars/1_scalar-10 17542587 67.59 ns/op BenchmarkSumScalars/2_scalars-10 10528258 114.1 ns/op BenchmarkSumScalars/4_scalars-10 6178672 197.0 ns/op BenchmarkSumScalars/8_scalars-10 3390189 355.5 ns/op BenchmarkSumScalars/16_scalars-10 1810102 664.6 ns/op BenchmarkSumScalars/20_scalars-10 1404478 852.1 ns/op BenchmarkSumPoints/1_point-10 78704 15069 ns/op BenchmarkSumPoints/2_points-10 53053 22634 ns/op BenchmarkSumPoints/4_points-10 31495 37971 ns/op BenchmarkSumPoints/8_points-10 17428 68906 ns/op BenchmarkSumPoints/16_points-10 9368 132542 ns/op BenchmarkSumPoints/20_points-10 7748 160958 ns/op BenchmarkSolveScalarPolynomial/1_coefficient-10 6145372 195.3 ns/op BenchmarkSolveScalarPolynomial/2_coefficients-10 3253008 361.1 ns/op BenchmarkSolveScalarPolynomial/4_coefficients-10 1749273 686.4 ns/op BenchmarkSolveScalarPolynomial/8_coefficients-10 897830 1357 ns/op BenchmarkSolveScalarPolynomial/16_coefficients-10 462337 2669 ns/op BenchmarkSolveScalarPolynomial/20_coefficients-10 370695 3263 ns/op BenchmarkSolvePointPolynomial/1_coefficient-10 73198 17317 ns/op BenchmarkSolvePointPolynomial/2_coefficients-10 14152 88587 ns/op BenchmarkSolvePointPolynomial/4_coefficients-10 4914 265079 ns/op BenchmarkSolvePointPolynomial/8_coefficients-10 2113 605937 ns/op BenchmarkSolvePointPolynomial/16_coefficients-10 920 1328468 ns/op BenchmarkSolvePointPolynomial/20_coefficients-10 732 1601354 ns/op BenchmarkSign-10 131737 9340 ns/op BenchmarkVerify-10 12024 99999 ns/op BenchmarkVerifyWithCustomGenerator-10 7956 154520 ns/op BenchmarkVerifyWithCustomLagrange-10 10000 104389 ns/op PASS ok github.com/bandprotocol/chain/v3/pkg/tss 55.895sAfter:
go test -run=^$ -bench=. ./pkg/tss goos: darwin goarch: arm64 pkg: github.com/bandprotocol/chain/v3/pkg/tss cpu: Apple M3 BenchmarkEncrypt-10 567440 1928 ns/op BenchmarkDecrypt-10 703724 1702 ns/op BenchmarkHash/1_byte-10 4603222 261.5 ns/op BenchmarkHash/4_bytes-10 4622518 260.3 ns/op BenchmarkHash/32_bytes-10 4561616 262.3 ns/op BenchmarkHash/128_bytes-10 4521471 265.7 ns/op BenchmarkHash/1024_bytes-10 652009 2104 ns/op BenchmarkHash/8096_bytes-10 74715 13853 ns/op BenchmarkSumScalars/1_scalar-10 17728346 65.99 ns/op BenchmarkSumScalars/2_scalars-10 10544089 139.3 ns/op BenchmarkSumScalars/4_scalars-10 5843629 199.2 ns/op BenchmarkSumScalars/8_scalars-10 3395602 354.2 ns/op BenchmarkSumScalars/16_scalars-10 1804046 673.1 ns/op BenchmarkSumScalars/20_scalars-10 1403095 853.8 ns/op BenchmarkSumPoints/1_point-10 78387 15264 ns/op BenchmarkSumPoints/2_points-10 52152 24108 ns/op BenchmarkSumPoints/4_points-10 30903 38840 ns/op BenchmarkSumPoints/8_points-10 16618 70281 ns/op BenchmarkSumPoints/16_points-10 9116 133503 ns/op BenchmarkSumPoints/20_points-10 7575 164217 ns/op BenchmarkSolveScalarPolynomial/1_coefficient-10 6180862 194.0 ns/op BenchmarkSolveScalarPolynomial/2_coefficients-10 3308318 362.9 ns/op BenchmarkSolveScalarPolynomial/4_coefficients-10 1745617 688.9 ns/op BenchmarkSolveScalarPolynomial/8_coefficients-10 898023 1325 ns/op BenchmarkSolveScalarPolynomial/16_coefficients-10 462050 2600 ns/op BenchmarkSolveScalarPolynomial/20_coefficients-10 370015 3256 ns/op BenchmarkSolvePointPolynomial/1_coefficient-10 73411 16180 ns/op BenchmarkSolvePointPolynomial/2_coefficients-10 13491 88832 ns/op BenchmarkSolvePointPolynomial/4_coefficients-10 4927 254178 ns/op BenchmarkSolvePointPolynomial/8_coefficients-10 2142 590076 ns/op BenchmarkSolvePointPolynomial/16_coefficients-10 1026 1271700 ns/op BenchmarkSolvePointPolynomial/20_coefficients-10 752 1643294 ns/op BenchmarkSign-10 121498 10410 ns/op BenchmarkVerify-10 10000 105062 ns/op BenchmarkVerifyWithCustomGenerator-10 7801 159191 ns/op BenchmarkVerifyWithCustomLagrange-10 10000 104541 ns/op PASS ok github.com/bandprotocol/chain/v3/pkg/tss 52.658sFixed: #XXXX
Implementation details
Please ensure the following requirements are met before submitting a pull request:
CHANGELOG_UNRELEASED.mdFiles changedtab in the Github PR explorer)