Commit 83b6dc7a authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Add std dev to UnboundedQueue bench for flavor

Summary: [Folly] Add std dev to `UnboundedQueue` bench for flavor.

Reviewed By: magedm

Differential Revision: D13192196

fbshipit-source-id: c702c0c6b5a788d4f02e6b87220f8a63b55f22cc
parent 147a597e
...@@ -317,9 +317,12 @@ uint64_t runBench(const std::string& name, int ops, const RepFunc& repFn) { ...@@ -317,9 +317,12 @@ uint64_t runBench(const std::string& name, int ops, const RepFunc& repFn) {
uint64_t max = 0; uint64_t max = 0;
uint64_t sum = 0; uint64_t sum = 0;
std::vector<uint64_t> durs(reps);
repFn(); // sometimes first run is outlier repFn(); // sometimes first run is outlier
for (int r = 0; r < reps; ++r) { for (int r = 0; r < reps; ++r) {
uint64_t dur = repFn(); uint64_t dur = repFn();
durs[r] = dur;
sum += dur; sum += dur;
min = std::min(min, dur); min = std::min(min, dur);
max = std::max(max, dur); max = std::max(max, dur);
...@@ -334,9 +337,16 @@ uint64_t runBench(const std::string& name, int ops, const RepFunc& repFn) { ...@@ -334,9 +337,16 @@ uint64_t runBench(const std::string& name, int ops, const RepFunc& repFn) {
const std::string unit = " ns"; const std::string unit = " ns";
uint64_t avg = sum / reps; uint64_t avg = sum / reps;
uint64_t res = min; uint64_t res = min;
uint64_t varsum = 0;
for (auto r = 0; r < reps; ++r) {
auto term = int64_t(reps * durs[r]) - int64_t(sum);
varsum += term * term;
}
uint64_t dev = uint64_t(std::sqrt(varsum) * std::pow(reps, -1.5));
std::cout << name; std::cout << name;
std::cout << " " << std::setw(4) << max / ops << unit; std::cout << " " << std::setw(4) << max / ops << unit;
std::cout << " " << std::setw(4) << avg / ops << unit; std::cout << " " << std::setw(4) << avg / ops << unit;
std::cout << " " << std::setw(4) << dev / ops << unit;
std::cout << " " << std::setw(4) << res / ops << unit; std::cout << " " << std::setw(4) << res / ops << unit;
std::cout << std::endl; std::cout << std::endl;
return res; return res;
...@@ -466,14 +476,15 @@ struct IntArray { ...@@ -466,14 +476,15 @@ struct IntArray {
}; };
void dottedLine() { void dottedLine() {
std::cout << ".............................................................." std::cout
<< "........................................................................"
<< std::endl; << std::endl;
} }
template <typename T> template <typename T>
void type_benches(const int np, const int nc, const std::string& name) { void type_benches(const int np, const int nc, const std::string& name) {
std::cout << name std::cout << name << "====================================================="
<< "===========================================" << std::endl; << std::endl;
if (np == 1 && nc == 1) { if (np == 1 && nc == 1) {
bench<USPSC, T, 0>(1, 1, "Unbounded SPSC try spin only "); bench<USPSC, T, 0>(1, 1, "Unbounded SPSC try spin only ");
bench<USPSC, T, 1>(1, 1, "Unbounded SPSC timed spin only "); bench<USPSC, T, 1>(1, 1, "Unbounded SPSC timed spin only ");
...@@ -515,14 +526,15 @@ void type_benches(const int np, const int nc, const std::string& name) { ...@@ -515,14 +526,15 @@ void type_benches(const int np, const int nc, const std::string& name) {
bench<FMPMC, T, 3>(np, nc, "folly::MPMC read "); bench<FMPMC, T, 3>(np, nc, "folly::MPMC read ");
bench<FMPMC, T, 4>(np, nc, "folly::MPMC tryReadUntil "); bench<FMPMC, T, 4>(np, nc, "folly::MPMC tryReadUntil ");
bench<FMPMC, T, 5>(np, nc, "folly::MPMC blockingRead "); bench<FMPMC, T, 5>(np, nc, "folly::MPMC blockingRead ");
std::cout << "==============================================================" std::cout
<< "========================================================================"
<< std::endl; << std::endl;
} }
void benches(const int np, const int nc) { void benches(const int np, const int nc) {
std::cout << "====================== " << std::setw(2) << np << " prod" std::cout << "====================== " << std::setw(2) << np << " prod"
<< " " << std::setw(2) << nc << " cons" << " " << std::setw(2) << nc << " cons"
<< " ======================" << std::endl; << " ================================" << std::endl;
type_benches<uint32_t>(np, nc, "=== uint32_t ======"); type_benches<uint32_t>(np, nc, "=== uint32_t ======");
// Benchmarks for other element sizes can be added as follows: // Benchmarks for other element sizes can be added as follows:
// type_benches<IntArray<4>>(np, nc, "=== IntArray<4> ==="); // type_benches<IntArray<4>>(np, nc, "=== IntArray<4> ===");
...@@ -532,7 +544,8 @@ TEST(UnboundedQueue, bench) { ...@@ -532,7 +544,8 @@ TEST(UnboundedQueue, bench) {
if (!FLAGS_bench) { if (!FLAGS_bench) {
return; return;
} }
std::cout << "==============================================================" std::cout
<< "========================================================================"
<< std::endl; << std::endl;
std::cout << std::setw(2) << FLAGS_reps << " reps of " << std::setw(8) std::cout << std::setw(2) << FLAGS_reps << " reps of " << std::setw(8)
<< FLAGS_ops << " handoffs\n"; << FLAGS_ops << " handoffs\n";
...@@ -542,9 +555,11 @@ TEST(UnboundedQueue, bench) { ...@@ -542,9 +555,11 @@ TEST(UnboundedQueue, bench) {
std::cout << "Using capacity " << FLAGS_capacity std::cout << "Using capacity " << FLAGS_capacity
<< " for folly::ProducerConsumerQueue and\n" << " for folly::ProducerConsumerQueue and\n"
<< "folly::MPMCQueue\n"; << "folly::MPMCQueue\n";
std::cout << "==============================================================" std::cout
<< "========================================================================"
<< std::endl; << std::endl;
std::cout << "Test name Max time Avg time Min time" std::cout
<< "Test name Max time Avg time Dev time Min time"
<< std::endl; << std::endl;
for (int nc : {1, 2, 4, 8, 16, 32}) { for (int nc : {1, 2, 4, 8, 16, 32}) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment