-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat: Add ScopedPauseTiming RAII helper #2157
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
Merged
+73
−0
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d5065cf
feat: Add ScopedPauseTiming RAII helper
dmah42 f671629
Bump astral-sh/setup-uv from 7.6.0 to 8.0.0 (#2160)
dependabot[bot] b8453cd
Bump lukka/get-cmake from 4.3.0 to 4.3.1 (#2159)
dependabot[bot] c37f533
Bump numpy from 2.4.3 to 2.4.4 in /tools (#2158)
dependabot[bot] 1ec5421
handle move operators
dmah42 0a27b8d
Merge branch 'main' into feature/scoped-pause-guard
dmah42 fae028f
Use manual time instead of real time for better repeatability
dmah42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
|
|
||
| #include <chrono> | ||
| #include <thread> | ||
|
|
||
| #include "benchmark/benchmark.h" | ||
| #include "output_test.h" | ||
|
|
||
| // BM_ScopedPause sleeps for 10ms in a ScopedPauseTiming block. | ||
| // The reported time should be much less than 10ms. | ||
| void BM_ScopedPause(benchmark::State& state) { | ||
| for (auto _ : state) { | ||
| benchmark::ScopedPauseTiming pause(state); | ||
| std::this_thread::sleep_for(std::chrono::milliseconds(10)); | ||
| state.SetIterationTime(0.0); | ||
| } | ||
| } | ||
| BENCHMARK(BM_ScopedPause)->UseManualTime()->Iterations(1); | ||
|
|
||
| void CheckResults(Results const& results) { | ||
| // Check that the real time is much less than the 10ms sleep time. | ||
| // Allow for up to 1ms of timing noise/overhead. | ||
| CHECK_FLOAT_RESULT_VALUE(results, "real_time", LT, 1e6, 0.0); | ||
| } | ||
| CHECK_BENCHMARK_RESULTS("BM_ScopedPause", &CheckResults); | ||
|
|
||
| int main(int argc, char* argv[]) { | ||
| benchmark::MaybeReenterWithoutASLR(argc, argv); | ||
| RunOutputTests(argc, argv); | ||
| return 0; | ||
| } | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd strongly suggest to use ManualTime for this, not rely on the system timers doing the right thing.