Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@EfesX
Copy link
Contributor

@EfesX EfesX commented Feb 14, 2025

Custom Benchmark::Setup and Benchmark::Teardown take std::function. So it is possible to pass any functor there

Fixes #1872

@google-cla
Copy link

google-cla bot commented Feb 14, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@LebedevRI
Copy link
Collaborator

I do believe we could theoretically do this now that C++03 support is gone.
Also, #1609 comes to mind.

@EfesX EfesX marked this pull request as draft February 14, 2025 20:41
}

Benchmark* Benchmark::Setup(void (*setup)(const benchmark::State&)) {
Benchmark* Benchmark::Setup(callback_function setup) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

(I don't know)

I don't remember what the best practice is, should it be taken by && and perhaps moved?

Copy link
Contributor Author

@EfesX EfesX Feb 15, 2025

Choose a reason for hiding this comment

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

It looks like you're right. It seems that && is a more appropriate way

@EfesX
Copy link
Contributor Author

EfesX commented Feb 15, 2025

Also, #1609 comes to mind.

I could try to work on this in a separate PR

@LebedevRI
Copy link
Collaborator

Where did the tests go?

1. move the definition of callback_function to the benchmark namespace. in order for the user to use this
2. add overloads for Stup/Teardown
@EfesX
Copy link
Contributor Author

EfesX commented Feb 15, 2025

Where did the tests go?

The tests are back

std::function is already nullptr by default. thus, there is no need to initialize its by by nullptr manually.

void function(const benchmark::State& /*unused*/) {}

int main(int argc, char** argv) {
Copy link
Member

Choose a reason for hiding this comment

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

this test doesn't appear to be, well, testing anything. can you please take a look at how the other tests are structured and see about making this more useful?

@dmah42
Copy link
Member

dmah42 commented Feb 20, 2025

if you can merge in the changes and mark this PR as ready to review i think we can get it landed.

Copy link
Collaborator

@LebedevRI LebedevRI left a comment

Choose a reason for hiding this comment

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

Seems reasonable-ish.

@EfesX EfesX marked this pull request as ready for review February 20, 2025 13:07
@LebedevRI LebedevRI merged commit ff5c94d into google:main Feb 20, 2025
84 of 86 checks passed
@LebedevRI
Copy link
Collaborator

@EfesX thank you!

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.

[FR] Let SetUp and TearDown be std::function

3 participants