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

feature request: clean up closure #57

Open
git-girl opened this issue Jun 8, 2024 · 2 comments
Open

feature request: clean up closure #57

git-girl opened this issue Jun 8, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@git-girl
Copy link

git-girl commented Jun 8, 2024

hey there :3

thanks for provding this library, so far i've really enjoyed using it :>
i really hope i didn't miss anything that this already exists sometimes i am a bit very silly when it comes to properly reading the docs.

request

adding an an optional closure that can be passed to a Bencher that is called after each bench run through but not counted towards the measurment time. (like i guess smth like bencher.with_cleanup(closure) that then runs somewhere at the end of bench_loop_threaded {hope i understood the code correctly there})

motivation

i am looking into benching some sql queries and i wanted to run DISCARD after every bench run so as to clear the caches a bit. and i think this is a general thing of wanting to clear a cache is something that comes up often in benching.

capacities on my end

i am doing this as a free time thing so i have time to look into this and can also imagine writing a pr. allthough i am not certain my code quality would be up to par but i mean i can try.

best regards

@nvzqz
Copy link
Owner

nvzqz commented Jun 11, 2024

You can accomplish this today with Drop by returning something from the benchmark, and it will run for every iteration. But it will be after the timing, so it depends on how caches are being used if multiple iterations are included in the sample. You might want to limit it with #[divan::bench(sample_size = 1)].

To properly add this feature, it shouldn't be hard to implement by internally using the DeferStore mechanism for handling Drop.

@nvzqz nvzqz added the enhancement New feature or request label Jun 11, 2024
@git-girl
Copy link
Author

hey thank you for your reply and sorry for this late reply!
i did try out the implementation via Drop and that felt like a nice api to use allthough i didn't figure out getting around the postgres cache even with the sample_size=1. i think i am gonna put this postgres endeavour to the side for now. i will try to find some time to try some things out with this. but i may be rather slow to get to work on it.

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

No branches or pull requests

2 participants