Add Benchmark::ThreadRange() version with increment instead of multiply#283
Conversation
|
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). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
|
✅ Build benchmark 401 completed (commit b457d0c0eb by @hydroo) |
|
I signed it! |
|
CLAs look good, thanks! |
FYI PR #286 makes PauseTiming() per thread instead of per-process so it doesn't perform synchronization and block the threads. |
|
Thanks for the info. |
| // Foo in 16 threads | ||
| Benchmark* ThreadRange(int min_threads, int max_threads); | ||
|
|
||
| Benchmark* ThreadRange2(int min_threads, int max_threads); |
There was a problem hiding this comment.
I would suggest DenseThreadRange(int min_threads, int max_threads, int stride=1) since it matches the DenseRange function we already have.
|
Alright so there are a couple things left to do.
static void BM_ThreadRanges(benchmark::State& st) {
switch (st.range(0)) {
case 1:
assert(st.threads == 1 || st.threads == 2 || st.threads == 3);
break;
case 2:
assert(st.threads == 1 || st.threads == 3);
break;
case 3:
assert(st.threads == 5 || st.threads == 8 || st.threads == 11 || st.threads == 14);
break;
default:
assert(false && "Invalid test case number");
}
while (st.KeepRunning()) {}
}
BENCHMARK(BM_ThreadRanges)->Arg(1)->DenseThreadRange(1, 3);
BENCHMARK(BM_ThreadRanges)->Arg(2)->DenseThreadRange(1, 3, 2);
BENCHMARK(BM_ThreadRanges)->Arg(3)->DenseThreadRange(5, 14, 3); |
|
Is there a clang-format file for this project? I just tried clang-format -style=Google on benchmark_api.h and it changed a lot lot. So that's probably not what you do. |
|
There is a config file now. It was just checked in today. |
|
When I make test, benchark_test.cc is not executed. Is there a non-manual way to run it? Or how is this intended? I add the test to the end of benchark_test.cc, ok? |
|
This clang format file seems to be for a clang version newer than 3.8 (Newest Ubuntu). |
|
Stick the test wherever makes sense and use --style=Google if the config doesn't work. |
|
I force pushed my master, since I had troubles with git. I used this opportunity to clean up my commits as well. It's now only two. |
|
❌ Build benchmark 442 failed (commit b9ba8c6b88 by @hydroo) |
|
Looks good to me! Thanks for the patch. |
|
To discuss some of your other comments:
PauseTiming now act's a lot differently. In particular it's thread-local and doesn't act as a barrier so hopefully this solves your problem. Also I'm looking into "thread pinning" as a feature, but I'm not sure what the correct way to pin the threads is. |
|
Thanks! Last Saturday I had big troubles getting my code to work in the benchmark harness, again. Can threads overtake each other in KeepRunning() or is there a barrier between iterations? As for SetIterationTime, I would also like to have the maximum of all threads and the time from the earliest Since I benchmark synchronization primitives I want to make sure (1) threads are not migrated during benchmark execution, (2) threads are placed in a sensible way (not 1, 3 on 2 cpus with 2 threads each, e.g.), perhaps I want to even place them individually myself because distances between CPUs affect performance. Last time I used |
Sorry but the barrier in I plan to add barrier functionality to
That shouldn't be a problem with the existing API. See the example below.
void SetupGlobalState();
void TeardownGlobalState();
std::vector<int> global_state;
static BM_Foo(benchmark::State& st) {
if (st.thread_index == 0) { // A single thread executes this setup.
SetupGlobalState();
}
PinCurrentThread(); // All thread execute this
while (st.KeepRunning()) { // No thread starts the loop until all threads are here.
/* ... */
} // No thread passes here until all threads are complete.
if (st.thread_index == 0) {
TeardownGlobalState();
}
}
Yeah I think
I think users will generally want to place the threads themselves. That's why IDK if this can be a library feature. Also it's super easy for users to pin threads today (see above).
No that's the way to do it. But as mentioned above it's not clear what to set the affinity to. |
Hi,
referring to #282.
Yes we do have up to 24 or 48 threads per board at the moment.
I use it for benchmarking synchronization algorithms. (Not a very common thing to do,)
I will probably need a few more things in the future like thread pinning and more accurate version of PauseTiming so I can make sure they leave at an exact time.
I'm not even sure google/benchmark is the right tool for the job. But it seems nice. The output, functionality and code is pretty simple and clear.
Motivating example: