lorawan-stack icon indicating copy to clipboard operation
lorawan-stack copied to clipboard

refactor: use b.Loop() to simplify the code and improve performance

Open changgesi opened this issue 1 month ago • 0 comments

Summary

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=. ./pkg/random -timeout=1h        
goos: darwin
goarch: arm64
pkg: go.thethings.network/lorawan-stack/v3/pkg/random
cpu: Apple M4
BenchmarkBytes-10     	 5909042	       201.1 ns/op
BenchmarkIntn-10      	11468240	       104.5 ns/op
BenchmarkString-10    	 4548926	       262.5 ns/op
PASS
ok  	go.thethings.network/lorawan-stack/v3/pkg/random	4.976s

After:

go test -run=^$ -bench=. ./pkg/random -timeout=1h
goos: darwin
goarch: arm64
pkg: go.thethings.network/lorawan-stack/v3/pkg/random
cpu: Apple M4
BenchmarkBytes-10     	 5336761	       220.6 ns/op
BenchmarkIntn-10      	11183427	       106.2 ns/op
BenchmarkString-10    	 4407140	       271.7 ns/op
PASS
ok  	go.thethings.network/lorawan-stack/v3/pkg/random	4.241s

...

Changes

  • ...
  • ...

Testing

Steps

...

Results
Regressions

...

Notes for Reviewers

...

Checklist

  • [ ] Scope: The referenced issue is addressed, there are no unrelated changes.
  • [ ] Compatibility: The changes are backwards compatible with existing API, storage, configuration and CLI, according to the compatibility commitments in README.md for the chosen target branch.
  • [ ] Documentation: Relevant documentation is added or updated.
  • [ ] Testing: The steps/process to test this feature are clearly explained including testing for regressions.
  • [ ] Infrastructure: If infrastructural changes (e.g., new RPC, configuration) are needed, a separate issue is created in the infrastructural repositories.
  • [ ] Changelog: Significant features, behavior changes, deprecations and fixes are added to CHANGELOG.md.
  • [x] Commits: Commit messages follow guidelines in CONTRIBUTING.md, there are no fixup commits left.

changgesi avatar Dec 11 '25 03:12 changgesi