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

feat(benchmark): add lifecycle hooks for enhanced benchmark control #56

Merged
merged 2 commits into from
Mar 9, 2024

Conversation

hendriknielaender
Copy link
Owner

Add Lifecycle Hooks

This PR introduces lifecycle hooks, providing users with greater control and flexibility over their benchmark setup and teardown processes. These hooks allow for custom actions at various stages of the benchmarking lifecycle, enabling precise environment management and setup/teardown operations.

New Features:

  • Lifecycle Hooks: Implement beforeAll, afterAll, beforeEach, and afterEach hooks.
    • beforeAll: Executes once before all benchmarks begin.
    • afterAll: Executes once after all benchmarks have completed.
    • beforeEach: Executes before each individual benchmark iteration.
    • afterEach: Executes after each individual benchmark iteration.

Use Cases:

These hooks are particularly beneficial for complex benchmarks requiring specific setup and teardown operations, ensuring each test runs under the right conditions and managing resources properly.

Implementation:

Hooks are optional and easy to integrate into existing tests with minimal configuration, defined within the LifecycleHooks struct and included in the benchmark Config struct. This enhancement aims to provide a seamless and flexible user experience for benchmarking.

Example Usage:

const hooks = .{
    .beforeAll = fn() void { /* global setup */ },
    .afterAll = fn() void { /* global teardown */ },
    .beforeEach = fn() void { /* per-test setup */ },
    .afterEach = fn() void { /* per-test teardown */ },
};
var config = Benchmark.Config{ .hooks = hooks };

closes #41

@hendriknielaender hendriknielaender added the enhancement New feature or request label Mar 7, 2024
@hendriknielaender hendriknielaender self-assigned this Mar 7, 2024
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.

Looks cool to me in principle! Up next, we would need an example that makes use of the hooks.

Besides, I was hoping for Zig 0.12 to be released around February, so we could make the upgrade to that version. But... seems like we need to wait some more.

@hendriknielaender
Copy link
Owner Author

we would need an example that makes use of the hooks

Good call, i have added an issue to tackle this. #58

Yeah as soon as 0.12 is released, we will upgrade.

@hendriknielaender hendriknielaender merged commit 1237f4b into main Mar 9, 2024
5 checks passed
bens pushed a commit to bens/zBench that referenced this pull request Mar 12, 2024
…endriknielaender#56)

* feat(benchmark): add lifecycle hooks for enhanced benchmark control

* chore: add hooks to README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Lifecycle Hooks
2 participants