Unstable benchmark excluding setup feature - #161281
Open
fereidani wants to merge 2 commits into
Open
Conversation
Collaborator
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR tries to resolve a missing feature by adding a new benchmarking method
iter_excluding_setup.This idea came from working on
vec::retainalgorithm when I noticed that benchmark has about 15% noise of preparing the benchmark data:This includes time to
clearandextendin benchmark time, which is not our benchmark target.As an algorithm improves through development this preparation noise increases and benchmark time becomes less reliable.
With this feature we can rewrite it as following:
In contrary,
iter_excluding_setuptimes exactly the retain part and ignores preparation phase.To achieve this we need to account for
Instant::nowsyscall overhead. I tested with both average and minimum sample of 1000 runs. I think worst caseminis more reliable than average. an empty functions benchmarks around 0ns-3ns on my laptop's 5850U cpu which is IMHO acceptable.If we account that
Instant::now()is 20ns, 1000 runs will be calculated in 20 microseconds once and will be reused after that, which is not a concern for any benchmark.I also removed single
Instant::now()sample from currentiterbenchmarks to try to slightly improve its accuracy for single runs or small benchmarks.This feature is also applicable and needed in current string benchmarks in
alloctests/bencheswhen allocation time is included ininsertbenchmarks resulting in about 100% noise:Rewrite with excluding setup sample:
We can also use this feature to benchmark exactly allocation and deallocation of an object, for example:
This is currently impossible to do with current available features, It will be also useful in benchmarking more complex data structures like hashmaps and linked lists too. (hash collisions, empty hashmap insertion, deallocation, allocation, etc.)
I only need this features to improve rust library itself, and there is no need for stabilization.