sapling/eden/fs/benchharness/Bench.cpp
Andres Suarez fbdb46f5cb Tidy up license headers
Reviewed By: chadaustin

Differential Revision: D17872966

fbshipit-source-id: cd60a364a2146f0dadbeca693b1d4a5d7c97ff63
2019-10-11 05:28:23 -07:00

43 lines
999 B
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/
#include "eden/fs/benchharness/Bench.h"
#include <inttypes.h>
#include <stdio.h>
#include <time.h>
namespace facebook {
namespace eden {
uint64_t getTime() noexcept {
timespec ts;
// CLOCK_MONOTONIC is subject in NTP adjustments. CLOCK_MONOTONIC_RAW would be
// better but these benchmarks are short and reading CLOCK_MONOTONIC takes 20
// ns and CLOCK_MONOTONIC_RAW takes 130 ns.
clock_gettime(CLOCK_MONOTONIC, &ts);
return ts.tv_sec * 1000000000 + ts.tv_nsec;
}
StatAccumulator measureClockOverhead() noexcept {
constexpr int N = 10000;
StatAccumulator accum;
uint64_t last = getTime();
for (int i = 0; i < N; ++i) {
uint64_t next = getTime();
uint64_t elapsed = next - last;
accum.add(elapsed);
last = next;
}
return accum;
}
} // namespace eden
} // namespace facebook