Skip to content

docs: document scalingFactor timer resolution and memory growth pitfalls#353

Open
vinayjn wants to merge 2 commits intoordo-one:mainfrom
vinayjn:docs/scaling-factor-timer-resolution
Open

docs: document scalingFactor timer resolution and memory growth pitfalls#353
vinayjn wants to merge 2 commits intoordo-one:mainfrom
vinayjn:docs/scaling-factor-timer-resolution

Conversation

@vinayjn
Copy link
Copy Markdown

@vinayjn vinayjn commented Apr 27, 2026

Description

Add guidance under the scalingFactor section for two common issues:

  • Timer granularity on Apple Silicon (~41.67 ns at 24 MHz) makes sub-100 ns benchmarks unreliable without an inner loop. Recommend .kilo for 1–500 ns operations and .mega for sub-nanosecond work.

  • Stateful mutation benchmarks with high scalingFactor can exhaust memory (e.g. .kilo × 10K iterations = 10M mutations). Show two mitigation patterns: capping maxIterations and using startMeasurement() to exclude periodic resets.

How Has This Been Tested?

Documentation-only change. Verified DocC renders correctly locally.

Minimal checklist:

  • I have performed a self-review of my own code
  • I have added DocC code-level documentation for any public interfaces exported by the package
  • I have added unit and/or integration tests that prove my fix is effective or that my feature works

Add guidance under the scalingFactor section for two common issues:

- Timer granularity on Apple Silicon (~41.67 ns at 24 MHz) makes
  sub-100 ns benchmarks unreliable without an inner loop. Recommend
  .kilo for 1–500 ns operations and .mega for sub-nanosecond work.

- Stateful mutation benchmarks with high scalingFactor can exhaust
  memory (e.g. .kilo × 10K iterations = 10M mutations). Show two
  mitigation patterns: capping maxIterations and using
  startMeasurement() to exclude periodic resets.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the documentation for writing benchmarks by adding sections on the scalingFactor and handling stateful benchmarks. The new content explains how to mitigate timer resolution issues on Apple Silicon and prevent memory exhaustion during high-iteration tests. Review feedback suggests clarifying that the benchmark closure is responsible for executing iterations, correcting the performance description of Date() creation, and highlighting that resetting state within the closure is the preferred method for maintaining measurement stability.

Comment thread Sources/Benchmark/Documentation.docc/WritingBenchmarks.md Outdated
Comment thread Sources/Benchmark/Documentation.docc/WritingBenchmarks.md Outdated
Comment thread Sources/Benchmark/Documentation.docc/WritingBenchmarks.md Outdated
Clarify that the closure performs iterations (not the framework),
fix incorrect "sub-nanosecond" characterization of Date(), and
recommend periodic state reset over maxIterations cap for stateful
benchmarks.
@hassila hassila requested a review from supersonicbyte April 28, 2026 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant