Skip to content

bench: fix iterators to actually iterate in benchmarks#781

Merged
samber merged 1 commit intosamber:masterfrom
d-enk:fix-seq-bench
Jan 26, 2026
Merged

bench: fix iterators to actually iterate in benchmarks#781
samber merged 1 commit intosamber:masterfrom
d-enk:fix-seq-bench

Conversation

@d-enk
Copy link
Contributor

@d-enk d-enk commented Jan 22, 2026

  • Consume iterators with for range instead of discarding with _ = Previously iterators were created but never consumed, giving misleading performance results (~0.3 ns/op) that only measured iterator creation
  • Add BenchmarkItDropLastWhile for testing DropLastWhile performance
  • Add BenchmarkItTrim for testing Trim performance
  • Add BenchmarkItTrimSuffix for testing TrimSuffix performance
  • Replace for better readability for i := 0; i < n; i++ with for i := range n

This fix ensures benchmarks measure actual iterator execution time rather than just iterator creation time, which is critical for lazy iterators that don't execute until consumed.

- Consume iterators with for range instead of discarding with _ =
  Previously iterators were created but never consumed, giving misleading
  performance results (~0.3 ns/op) that only measured iterator creation
- Add BenchmarkItDropLastWhile for testing DropLastWhile performance
- Add BenchmarkItTrim for testing Trim performance
- Add BenchmarkItTrimSuffix for testing TrimSuffix performance
- Replace for better readability `for i := 0; i < n; i++` with `for i := range n`

This fix ensures benchmarks measure actual iterator execution time
rather than just iterator creation time, which is critical for lazy
iterators that don't execute until consumed.
@codecov
Copy link

codecov bot commented Jan 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.18%. Comparing base (2859d73) to head (ca08dc4).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #781   +/-   ##
=======================================
  Coverage   94.18%   94.18%           
=======================================
  Files          18       18           
  Lines        2872     2872           
=======================================
  Hits         2705     2705           
  Misses        151      151           
  Partials       16       16           
Flag Coverage Δ
unittests 94.18% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@samber samber merged commit 8211383 into samber:master Jan 26, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants