refactor: use b.Loop() to simplify the code and improve performance #202
+4
−4
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
Before:
go test -run=^$ -bench=. ./util/base58 goos: darwin goarch: arm64 pkg: github.com/MixinNetwork/mixin/util/base58 cpu: Apple M4 BenchmarkBase58Encode_5K-10 1257 958575 ns/op 5.22 MB/s BenchmarkBase58Encode_100K-10 3 377777069 ns/op 0.26 MB/s BenchmarkBase58Decode_5K-10 13212 91630 ns/op 74.53 MB/s BenchmarkBase58Decode_100K-10 42 28674206 ns/op 4.76 MB/s PASS ok github.com/MixinNetwork/mixin/util/base58 8.076sAfter:
go test -run=^$ -bench=. ./util/base58 goos: darwin goarch: arm64 pkg: github.com/MixinNetwork/mixin/util/base58 cpu: Apple M4 BenchmarkBase58Encode_5K-10 1269 945163 ns/op 5.29 MB/s BenchmarkBase58Encode_100K-10 3 378859333 ns/op 0.26 MB/s BenchmarkBase58Decode_5K-10 13183 91083 ns/op 74.98 MB/s BenchmarkBase58Decode_100K-10 40 28572274 ns/op 4.78 MB/s PASS ok github.com/MixinNetwork/mixin/util/base58 5.387s