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

Allow passing of state between startup/shutdown code and the actual benchmark inside the closure #252

Open
hassila opened this issue May 22, 2024 · 0 comments

Comments

@hassila
Copy link
Contributor

hassila commented May 22, 2024

Would be nice to streamline this a bit;

API suggestion:

it would be extremely cool, if we could return something from the setup hook that is then passed to the measure closure and the teardown hook

Like this:

    public convenience init?<each Setup>(
        _ name: String,
        configuration: Benchmark.Configuration = Benchmark.defaultConfiguration,
        closure: @escaping (Benchmark, repeat each Setup) async -> (),
        setup: () async throws -> (repeat each Setup),
        teardown: (repeat each Setup) async throws -> ()
    )

this way we don’t need to capture values outside the closures - to have them handy in setup and teardown 🙂

an alternative spelling could be this:

    public convenience init?<each Setup>(
        _ name: String,
        configuration: Benchmark.Configuration = Benchmark.defaultConfiguration,
        closure: @escaping (((Benchmark) async throws -> ()) async throws -> ()) async throws -> ()
    )

which would result in:

Benchmark("my-cool-benchmark") { measure in
    // my setup code
    measure { benchmark in // handing control to the benchmark framework. closure can be invoked multiple times

    }
    // my teardown code
}

Could do stuff like e.g.

Benchmark("my-cool-benchmark") { measure in
    let pool = SomeConnectionPool()

    await withTaskGroup { taskGroup in
        taskGroup.addTask { await pool.run() }
        measure { benchmark in // handing control to the benchmark framework. closure can be invoked multiple times
            // do stuff with the pool
        }

        taskGroup.cancelAll()
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant