Skip to content

Commit afffbb1

Browse files
author
MarcoFalke
committed
Merge #19710: bench: Prevent thread oversubscription and decreases the variance of result values
3edc4e3 bench: Prevent thread oversubscription (Hennadii Stepanov) ce3e6a7 bench: Allow skip benchmark (Hennadii Stepanov) Pull request description: Split out from #18710. Some results (borrowed from #18710): ![89121718-a3329800-d4c1-11ea-8bd1-66da20619696](https://user-images.githubusercontent.com/32963518/90146614-ecb89800-dd89-11ea-80fe-bac0e46e735e.png) ACKs for top commit: fjahr: Code review ACK 3edc4e3 Tree-SHA512: df7413ec9ea326564a8e8de54752c9d1444ff7de34edb03e1e0c2120fc333e4640767fdbe3e87eab6a7b389a4863c02e22ad2ae0dbf139fad6a9b85e00f563b4
2 parents 5c910a6 + 3edc4e3 commit afffbb1

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/bench/bench.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ void benchmark::BenchRunner::RunAll(const Args& args)
7070
}
7171
std::cout << bench.complexityBigO() << std::endl;
7272
}
73-
benchmarkResults.push_back(bench.results().back());
73+
74+
if (!bench.results().empty()) {
75+
benchmarkResults.push_back(bench.results().back());
76+
}
7477
}
7578

7679
GenerateTemplateResults(benchmarkResults, args.output_csv, "# Benchmark, evals, iterations, total, min, max, median\n"

src/bench/checkqueue.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
#include <vector>
1616

17-
18-
static const int MIN_CORES = 2;
1917
static const size_t BATCHES = 101;
2018
static const size_t BATCH_SIZE = 30;
2119
static const int PREVECTOR_SIZE = 28;
@@ -26,6 +24,9 @@ static const unsigned int QUEUE_BATCH_SIZE = 128;
2624
// and there is a little bit of work done between calls to Add.
2725
static void CCheckQueueSpeedPrevectorJob(benchmark::Bench& bench)
2826
{
27+
// We shouldn't ever be running with the checkqueue on a single core machine.
28+
if (GetNumCores() <= 1) return;
29+
2930
const ECCVerifyHandle verify_handle;
3031
ECC_Start();
3132

@@ -44,7 +45,9 @@ static void CCheckQueueSpeedPrevectorJob(benchmark::Bench& bench)
4445
};
4546
CCheckQueue<PrevectorJob> queue {QUEUE_BATCH_SIZE};
4647
boost::thread_group tg;
47-
for (auto x = 0; x < std::max(MIN_CORES, GetNumCores()); ++x) {
48+
// The main thread should be counted to prevent thread oversubscription, and
49+
// to decrease the variance of benchmark results.
50+
for (auto x = 0; x < GetNumCores() - 1; ++x) {
4851
tg.create_thread([&]{queue.Thread();});
4952
}
5053

0 commit comments

Comments
 (0)