Skip to content

Use std.time.Timer in benchmarks instead of nanoTimestamp - #145

Merged
lalinsky merged 1 commit into
mainfrom
benchmarks-use-timer
Nov 16, 2025
Merged

lalinsky merged 1 commit into
mainfrom
benchmarks-use-timer

Conversation

@lalinsky

Copy link
Copy Markdown
Owner

Summary

  • Updated echo_server.zig and ping_pong.zig to use std.time.Timer instead of std.time.nanoTimestamp()
  • concurrent_queue_bench.zig was already using the Timer API
  • This provides more accurate and portable timing measurements

Changes

  • Replaced manual timestamp calculations with Timer.start() and timer.read()
  • Simplified code by removing intermediate timestamp variables and calculations

@coderabbitai

coderabbitai Bot commented Nov 16, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Both benchmark files replaced manual nanoTimestamp() pairs with Timer-based elapsed time measurement. Round-trip latencies now record via timer.read() instead of explicit end-start subtraction. Control flow and measurement patterns remain unchanged.

Changes

Cohort / File(s) Summary
Timer Refactoring
benchmarks/echo_server.zig, benchmarks/ping_pong.zig
Replaced nanoTimestamp() pairs with Timer.start() and timer.read() for elapsed time measurement. Removed manual end-start difference calculations. In ping_pong.zig, added defer-based task lifecycle management for spawned tasks.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Consistent refactoring pattern applied across both files with minimal deviation
  • Straightforward substitution of timing APIs without introducing new logic
  • Task lifecycle management in ping_pong.zig is straightforward defer usage
  • Verify timer initialization and that read() captures the intended measurement window in both files

Poem

⏱️ Ticking clocks gave way to timers clean,
No more subtraction in between,
Read the elapsed, simple and true,
Benchmarks now know what they measure through. 🚀

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title directly matches the main change: replacing nanoTimestamp() calls with std.time.Timer across benchmark files.
Description check ✅ Passed The description accurately covers the changes made, explaining what was replaced and why (accuracy and portability).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch benchmarks-use-timer

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dc6a76c and bf86f2c.

📒 Files selected for processing (2)
  • benchmarks/echo_server.zig (4 hunks)
  • benchmarks/ping_pong.zig (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test (windows-latest)
🔇 Additional comments (4)
benchmarks/ping_pong.zig (2)

41-41: Timer usage is correct.

Starting the timer before spawning tasks and reading after runtime.run() accurately measures the benchmark duration. Monotonic timing avoids system clock issues that could affect nanoTimestamp.

Also applies to: 53-53


44-45: Good addition of task cleanup.

The defer statements ensure tasks are canceled when the function exits. This is proper resource management even though the tasks should complete normally.

Also applies to: 47-48

benchmarks/echo_server.zig (2)

69-69: Per-message latency measurement is accurate.

Starting a timer before each write and reading after the response correctly captures round-trip time. Timer creation overhead is negligible compared to network I/O.

Also applies to: 80-80


108-108: Benchmark timing is correct.

Timer measures the full duration from before spawning clients until all complete. The spawning overhead is included but negligible compared to the actual message processing time.

Also applies to: 125-125


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@lalinsky
lalinsky merged commit 6f6c4d0 into main Nov 16, 2025
@lalinsky
lalinsky deleted the benchmarks-use-timer branch November 16, 2025 19:32
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.

1 participant