Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maximum number of iterations limited by type #98

Open
FObersteiner opened this issue Feb 2, 2025 · 2 comments
Open

Maximum number of iterations limited by type #98

FObersteiner opened this issue Feb 2, 2025 · 2 comments
Assignees

Comments

@FObersteiner
Copy link
Collaborator

FObersteiner commented Feb 2, 2025

Hi there, I was wondering if there was a specific reason that the iterations counter is of type u16;

pub const Config = struct {
    /// Number of iterations the benchmark has been run. Initialized to 0.
    /// If 0 then zBench will calculate an value.
    iterations: u16 = 0,

I was playing around with some small functions the other day, and found that benchmark results using zbench became much more stable at numbers of iterations being significantly higher than u16 max. So, would it hurt to make the counter a u32?

@FObersteiner FObersteiner self-assigned this Feb 2, 2025
@hendriknielaender
Copy link
Owner

Hey @FObersteiner, the u16 was chosen because it’s sufficient for most benchmarks and keeps the configuration lightweight.

It could make sense to set higher iteration counts (beyond 65,535) for microbenchmarks. For me switching to a u32 makes sense, and there is no inherent harm in changing the iterations counter to a u32.

Feel free to open a PR that updates the iterations counter and any related configuration fields (like max_iterations).

@FObersteiner
Copy link
Collaborator Author

OK I'll make a PR tonight. 2 more bytes here and there won't hurt I guess ;-) Micro-benchmarks might not be the aim of zbench, however I think we can still achieve stable results for small functions, at least that's my experience. They might not be totally accurate (see baseline discussion), but still serve well for relative comparisons.

If a user doesn't specify a number of iterations, zbench will still limit them, either by Config.max_iterations or Config.time_budget_ns - while I'm at it, I'll check the limiting mechanism.

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

No branches or pull requests

2 participants