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

Added init/deinit to BenchmarkResults and updated examples #51

Merged
merged 1 commit into from
Feb 23, 2024

Conversation

Bryysen
Copy link
Collaborator

@Bryysen Bryysen commented Feb 19, 2024

This was done to circumvent #49, which is (most likely) caused by a bug in the compiler. Closes #49.

This was done to circumvent hendriknielaender#49, which is (most likely) caused by a
bug in the compiler.
@Bryysen
Copy link
Collaborator Author

Bryysen commented Feb 19, 2024

This was kind of a headache to get to the bottom of.. this solution didn't feel great but it's the one that requires the least amount of work for now. The alternative was of course to drop the buffered std-out writer all-together.

Calling getStdOut() inside a function seems to circumvent the issue, which is the reason for adding the BenchmarkResults.init function to do the initialization, instead of initializing its fields using default values.

@Bryysen Bryysen requested a review from FObersteiner February 19, 2024 22:48
@Bryysen Bryysen mentioned this pull request Feb 20, 2024
8 tasks
Copy link
Collaborator

@FObersteiner FObersteiner left a comment

Choose a reason for hiding this comment

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

I guess this does it as a temporary work-around. In general, I think there's two things that should be on the agenda:

  • clarify (by a use-case maybe) why there is a configurable writer instead of a hard-coded buffered writer to stdout
  • revise benchmark setup and run methods. Thinking as a new user, I feel it can be confusing which part needs to initialized (why do I need to set up results and benchmark separately?) and which part needs to be de-initialized (why the results? why not the benchmark? why not the allocator?)

@hendriknielaender
Copy link
Owner

hendriknielaender commented Feb 21, 2024

I guess this does it as a temporary work-around. In general, I think there's two things that should be on the agenda:

  • clarify (by a use-case maybe) why there is a configurable writer instead of a hard-coded buffered writer to stdout
  • revise benchmark setup and run methods. Thinking as a new user, I feel it can be confusing which part needs to initialized (why do I need to set up results and benchmark separately?) and which part needs to be de-initialized (why the results? why not the benchmark? why not the allocator?)

I also think the api could be leaner, something like this should do the job:

    var bench = Benchmark.init(std.heap.page_allocator, .{
        .iterations = 10,
    });
    defer bench.deinit();
    try bench.add("basic example", basicfn);
    try bench.add("sleep example", sleepfn);
    try bench.run();

But good points - i will open an issue for this to move the discussion. #52

Also from my side for now i think it does the job, feel free to merge it 👍

@Bryysen Bryysen merged commit 2cbbfa9 into hendriknielaender:main Feb 23, 2024
5 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.

BenchmarkResults "out_stream" field setup fails on Windows
3 participants