Merge pull request #8150 from sfc-gh-tclinkenbeard/fast-iteration-flowbench

Use faster `KeepRunning` loops in `flowbench`
This commit is contained in:
Jingyu Zhou 2022-09-12 09:29:29 -07:00 committed by GitHub
commit e415a963d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 20 additions and 23 deletions

View File

@ -47,7 +47,7 @@ static void bench_encrypt(benchmark::State& state) {
auto key = StreamCipherKey::getGlobalCipherKey();
auto iv = getRandomIV();
auto data = getKey(bytes);
while (state.KeepRunning()) {
for (auto _ : state) {
for (int chunk = 0; chunk < chunks; ++chunk) {
benchmark::DoNotOptimize(encrypt(key, iv, data.begin() + chunk * chunkSize, chunkSize));
}
@ -64,7 +64,7 @@ static void bench_decrypt(benchmark::State& state) {
auto iv = getRandomIV();
auto data = getKey(bytes);
auto encrypted = encrypt(key, iv, data.begin(), data.size());
while (state.KeepRunning()) {
for (auto _ : state) {
Arena arena;
DecryptionStreamCipher decryptor(key, iv);
for (int chunk = 0; chunk < chunks; ++chunk) {

View File

@ -58,7 +58,7 @@ template <HashType hashType>
static void bench_hash(benchmark::State& state) {
auto length = 1 << state.range(0);
auto key = getKey(length);
while (state.KeepRunning()) {
for (auto _ : state) {
hash<hashType>(key, length);
}
state.SetItemsProcessed(static_cast<long>(state.iterations()));

View File

@ -50,7 +50,7 @@ static void bench_iterate(benchmark::State& state) {
auto kv = getKV(size, size);
ListImpl mutations;
populate(mutations, items, size, kv.key, kv.value);
while (state.KeepRunning()) {
for (auto _ : state) {
for (const auto& mutation : mutations) {
benchmark::DoNotOptimize(mutation);
}

View File

@ -31,7 +31,7 @@ static void bench_memcmp(benchmark::State& state) {
memset(b2.get(), 0, kLength);
b2.get()[kLength - 1] = 1;
while (state.KeepRunning()) {
for (auto _ : state) {
benchmark::DoNotOptimize(memcmp(b1.get(), b2.get(), kLength));
}
}
@ -42,7 +42,7 @@ static void bench_memcpy(benchmark::State& state) {
std::unique_ptr<char[]> b2{ new char[kLength] };
memset(b1.get(), 0, kLength);
while (state.KeepRunning()) {
for (auto _ : state) {
benchmark::DoNotOptimize(memcpy(b2.get(), b1.get(), kLength));
}
}

View File

@ -39,7 +39,7 @@ static const std::array<MutationRef, 5> mutations = {
static void bench_check_metadata1(benchmark::State& state) {
const auto& m = mutations[state.range(0)];
while (state.KeepRunning()) {
for (auto _ : state) {
benchmark::DoNotOptimize(KeyRangeRef(m.param1, m.param2).intersects(systemKeys));
}
state.SetItemsProcessed(static_cast<long>(state.iterations()));
@ -47,7 +47,7 @@ static void bench_check_metadata1(benchmark::State& state) {
static void bench_check_metadata2(benchmark::State& state) {
const auto& m = mutations[state.range(0)];
while (state.KeepRunning()) {
for (auto _ : state) {
benchmark::DoNotOptimize(m.param2.size() > 1 && m.param2[0] == systemKeys.begin[0]);
}
state.SetItemsProcessed(static_cast<long>(state.iterations()));

View File

@ -35,7 +35,7 @@ static void bench_populate(benchmark::State& state) {
size_t items = state.range(0);
size_t size = state.range(1);
auto kv = getKV(size, size);
while (state.KeepRunning()) {
for (auto _ : state) {
Standalone<VectorRef<MutationRef>> mutations;
mutations.reserve(mutations.arena(), items);
for (int i = 0; i < items; ++i) {

View File

@ -23,9 +23,8 @@
#include "flow/IRandom.h"
static void bench_random(benchmark::State& state) {
while (state.KeepRunning()) {
double r = deterministicRandom()->random01();
benchmark::DoNotOptimize(r);
for (auto _ : state) {
benchmark::DoNotOptimize(deterministicRandom()->random01());
}
state.SetItemsProcessed(static_cast<long>(state.iterations()));
}

View File

@ -71,7 +71,7 @@ struct Factory<RefType::FlowReferenceThreadSafe> {
template <RefType refType>
static void bench_ref_create_and_destroy(benchmark::State& state) {
while (state.KeepRunning()) {
for (auto _ : state) {
auto ptr = Factory<refType>::create();
benchmark::DoNotOptimize(ptr);
Factory<refType>::cleanup(ptr);
@ -82,7 +82,7 @@ static void bench_ref_create_and_destroy(benchmark::State& state) {
template <RefType refType>
static void bench_ref_copy(benchmark::State& state) {
auto ptr = Factory<refType>::create();
while (state.KeepRunning()) {
for (auto _ : state) {
auto ptr2 = ptr;
benchmark::DoNotOptimize(ptr2);
}

View File

@ -23,17 +23,15 @@
#include "flow/Platform.h"
static void bench_timer(benchmark::State& state) {
while (state.KeepRunning()) {
double time = timer();
benchmark::DoNotOptimize(time);
for (auto _ : state) {
benchmark::DoNotOptimize(timer());
}
state.SetItemsProcessed(static_cast<long>(state.iterations()));
}
static void bench_timer_monotonic(benchmark::State& state) {
while (state.KeepRunning()) {
double time = timer_monotonic();
benchmark::DoNotOptimize(time);
for (auto _ : state) {
benchmark::DoNotOptimize(timer_monotonic());
}
state.SetItemsProcessed(static_cast<long>(state.iterations()));
}

View File

@ -34,7 +34,7 @@ static void bench_vv_getdelta(benchmark::State& benchState) {
i = 0;
const int64_t numDeltas = benchState.range(1);
while (benchState.KeepRunning()) {
for (auto _ : benchState) {
vv.setVersion(Tag(0, i++), ++version);
i %= tags;

View File

@ -41,7 +41,7 @@ static void bench_serializable_traits_version(benchmark::State& state) {
size_t size = 0;
VersionVector deserializedVV;
while (state.KeepRunning()) {
for (auto _ : state) {
Standalone<StringRef> msg = ObjectWriter::toValue(serializedVV, Unversioned());
// Capture the serialized buffer size.
@ -71,7 +71,7 @@ static void bench_dynamic_size_traits_version(benchmark::State& state) {
size_t size = 0;
VersionVector deserializedVV;
while (state.KeepRunning()) {
for (auto _ : state) {
size = dynamic_size_traits<VersionVector>::size(serializedVV, context);
uint8_t* buf = context.allocate(size);