mirror of
https://github.com/apple/foundationdb.git
synced 2025-05-15 02:18:39 +08:00
Use faster KeepRunning loops in flowbench
This commit is contained in:
parent
bc47f90aff
commit
7a870d395a
@ -47,7 +47,7 @@ static void bench_encrypt(benchmark::State& state) {
|
|||||||
auto key = StreamCipherKey::getGlobalCipherKey();
|
auto key = StreamCipherKey::getGlobalCipherKey();
|
||||||
auto iv = getRandomIV();
|
auto iv = getRandomIV();
|
||||||
auto data = getKey(bytes);
|
auto data = getKey(bytes);
|
||||||
while (state.KeepRunning()) {
|
for (auto _ : state) {
|
||||||
for (int chunk = 0; chunk < chunks; ++chunk) {
|
for (int chunk = 0; chunk < chunks; ++chunk) {
|
||||||
benchmark::DoNotOptimize(encrypt(key, iv, data.begin() + chunk * chunkSize, chunkSize));
|
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 iv = getRandomIV();
|
||||||
auto data = getKey(bytes);
|
auto data = getKey(bytes);
|
||||||
auto encrypted = encrypt(key, iv, data.begin(), data.size());
|
auto encrypted = encrypt(key, iv, data.begin(), data.size());
|
||||||
while (state.KeepRunning()) {
|
for (auto _ : state) {
|
||||||
Arena arena;
|
Arena arena;
|
||||||
DecryptionStreamCipher decryptor(key, iv);
|
DecryptionStreamCipher decryptor(key, iv);
|
||||||
for (int chunk = 0; chunk < chunks; ++chunk) {
|
for (int chunk = 0; chunk < chunks; ++chunk) {
|
||||||
|
@ -58,7 +58,7 @@ template <HashType hashType>
|
|||||||
static void bench_hash(benchmark::State& state) {
|
static void bench_hash(benchmark::State& state) {
|
||||||
auto length = 1 << state.range(0);
|
auto length = 1 << state.range(0);
|
||||||
auto key = getKey(length);
|
auto key = getKey(length);
|
||||||
while (state.KeepRunning()) {
|
for (auto _ : state) {
|
||||||
hash<hashType>(key, length);
|
hash<hashType>(key, length);
|
||||||
}
|
}
|
||||||
state.SetItemsProcessed(static_cast<long>(state.iterations()));
|
state.SetItemsProcessed(static_cast<long>(state.iterations()));
|
||||||
|
@ -50,7 +50,7 @@ static void bench_iterate(benchmark::State& state) {
|
|||||||
auto kv = getKV(size, size);
|
auto kv = getKV(size, size);
|
||||||
ListImpl mutations;
|
ListImpl mutations;
|
||||||
populate(mutations, items, size, kv.key, kv.value);
|
populate(mutations, items, size, kv.key, kv.value);
|
||||||
while (state.KeepRunning()) {
|
for (auto _ : state) {
|
||||||
for (const auto& mutation : mutations) {
|
for (const auto& mutation : mutations) {
|
||||||
benchmark::DoNotOptimize(mutation);
|
benchmark::DoNotOptimize(mutation);
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ static void bench_memcmp(benchmark::State& state) {
|
|||||||
memset(b2.get(), 0, kLength);
|
memset(b2.get(), 0, kLength);
|
||||||
b2.get()[kLength - 1] = 1;
|
b2.get()[kLength - 1] = 1;
|
||||||
|
|
||||||
while (state.KeepRunning()) {
|
for (auto _ : state) {
|
||||||
benchmark::DoNotOptimize(memcmp(b1.get(), b2.get(), kLength));
|
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] };
|
std::unique_ptr<char[]> b2{ new char[kLength] };
|
||||||
memset(b1.get(), 0, kLength);
|
memset(b1.get(), 0, kLength);
|
||||||
|
|
||||||
while (state.KeepRunning()) {
|
for (auto _ : state) {
|
||||||
benchmark::DoNotOptimize(memcpy(b2.get(), b1.get(), kLength));
|
benchmark::DoNotOptimize(memcpy(b2.get(), b1.get(), kLength));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ static const std::array<MutationRef, 5> mutations = {
|
|||||||
|
|
||||||
static void bench_check_metadata1(benchmark::State& state) {
|
static void bench_check_metadata1(benchmark::State& state) {
|
||||||
const auto& m = mutations[state.range(0)];
|
const auto& m = mutations[state.range(0)];
|
||||||
while (state.KeepRunning()) {
|
for (auto _ : state) {
|
||||||
benchmark::DoNotOptimize(KeyRangeRef(m.param1, m.param2).intersects(systemKeys));
|
benchmark::DoNotOptimize(KeyRangeRef(m.param1, m.param2).intersects(systemKeys));
|
||||||
}
|
}
|
||||||
state.SetItemsProcessed(static_cast<long>(state.iterations()));
|
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) {
|
static void bench_check_metadata2(benchmark::State& state) {
|
||||||
const auto& m = mutations[state.range(0)];
|
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]);
|
benchmark::DoNotOptimize(m.param2.size() > 1 && m.param2[0] == systemKeys.begin[0]);
|
||||||
}
|
}
|
||||||
state.SetItemsProcessed(static_cast<long>(state.iterations()));
|
state.SetItemsProcessed(static_cast<long>(state.iterations()));
|
||||||
|
@ -35,7 +35,7 @@ static void bench_populate(benchmark::State& state) {
|
|||||||
size_t items = state.range(0);
|
size_t items = state.range(0);
|
||||||
size_t size = state.range(1);
|
size_t size = state.range(1);
|
||||||
auto kv = getKV(size, size);
|
auto kv = getKV(size, size);
|
||||||
while (state.KeepRunning()) {
|
for (auto _ : state) {
|
||||||
Standalone<VectorRef<MutationRef>> mutations;
|
Standalone<VectorRef<MutationRef>> mutations;
|
||||||
mutations.reserve(mutations.arena(), items);
|
mutations.reserve(mutations.arena(), items);
|
||||||
for (int i = 0; i < items; ++i) {
|
for (int i = 0; i < items; ++i) {
|
||||||
|
@ -23,9 +23,8 @@
|
|||||||
#include "flow/IRandom.h"
|
#include "flow/IRandom.h"
|
||||||
|
|
||||||
static void bench_random(benchmark::State& state) {
|
static void bench_random(benchmark::State& state) {
|
||||||
while (state.KeepRunning()) {
|
for (auto _ : state) {
|
||||||
double r = deterministicRandom()->random01();
|
benchmark::DoNotOptimize(deterministicRandom()->random01());
|
||||||
benchmark::DoNotOptimize(r);
|
|
||||||
}
|
}
|
||||||
state.SetItemsProcessed(static_cast<long>(state.iterations()));
|
state.SetItemsProcessed(static_cast<long>(state.iterations()));
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ struct Factory<RefType::FlowReferenceThreadSafe> {
|
|||||||
|
|
||||||
template <RefType refType>
|
template <RefType refType>
|
||||||
static void bench_ref_create_and_destroy(benchmark::State& state) {
|
static void bench_ref_create_and_destroy(benchmark::State& state) {
|
||||||
while (state.KeepRunning()) {
|
for (auto _ : state) {
|
||||||
auto ptr = Factory<refType>::create();
|
auto ptr = Factory<refType>::create();
|
||||||
benchmark::DoNotOptimize(ptr);
|
benchmark::DoNotOptimize(ptr);
|
||||||
Factory<refType>::cleanup(ptr);
|
Factory<refType>::cleanup(ptr);
|
||||||
@ -82,7 +82,7 @@ static void bench_ref_create_and_destroy(benchmark::State& state) {
|
|||||||
template <RefType refType>
|
template <RefType refType>
|
||||||
static void bench_ref_copy(benchmark::State& state) {
|
static void bench_ref_copy(benchmark::State& state) {
|
||||||
auto ptr = Factory<refType>::create();
|
auto ptr = Factory<refType>::create();
|
||||||
while (state.KeepRunning()) {
|
for (auto _ : state) {
|
||||||
auto ptr2 = ptr;
|
auto ptr2 = ptr;
|
||||||
benchmark::DoNotOptimize(ptr2);
|
benchmark::DoNotOptimize(ptr2);
|
||||||
}
|
}
|
||||||
|
@ -23,17 +23,15 @@
|
|||||||
#include "flow/Platform.h"
|
#include "flow/Platform.h"
|
||||||
|
|
||||||
static void bench_timer(benchmark::State& state) {
|
static void bench_timer(benchmark::State& state) {
|
||||||
while (state.KeepRunning()) {
|
for (auto _ : state) {
|
||||||
double time = timer();
|
benchmark::DoNotOptimize(timer());
|
||||||
benchmark::DoNotOptimize(time);
|
|
||||||
}
|
}
|
||||||
state.SetItemsProcessed(static_cast<long>(state.iterations()));
|
state.SetItemsProcessed(static_cast<long>(state.iterations()));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bench_timer_monotonic(benchmark::State& state) {
|
static void bench_timer_monotonic(benchmark::State& state) {
|
||||||
while (state.KeepRunning()) {
|
for (auto _ : state) {
|
||||||
double time = timer_monotonic();
|
benchmark::DoNotOptimize(timer_monotonic());
|
||||||
benchmark::DoNotOptimize(time);
|
|
||||||
}
|
}
|
||||||
state.SetItemsProcessed(static_cast<long>(state.iterations()));
|
state.SetItemsProcessed(static_cast<long>(state.iterations()));
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ static void bench_vv_getdelta(benchmark::State& benchState) {
|
|||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
const int64_t numDeltas = benchState.range(1);
|
const int64_t numDeltas = benchState.range(1);
|
||||||
while (benchState.KeepRunning()) {
|
for (auto _ : benchState) {
|
||||||
vv.setVersion(Tag(0, i++), ++version);
|
vv.setVersion(Tag(0, i++), ++version);
|
||||||
i %= tags;
|
i %= tags;
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ static void bench_serializable_traits_version(benchmark::State& state) {
|
|||||||
|
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
VersionVector deserializedVV;
|
VersionVector deserializedVV;
|
||||||
while (state.KeepRunning()) {
|
for (auto _ : state) {
|
||||||
Standalone<StringRef> msg = ObjectWriter::toValue(serializedVV, Unversioned());
|
Standalone<StringRef> msg = ObjectWriter::toValue(serializedVV, Unversioned());
|
||||||
|
|
||||||
// Capture the serialized buffer size.
|
// Capture the serialized buffer size.
|
||||||
@ -71,7 +71,7 @@ static void bench_dynamic_size_traits_version(benchmark::State& state) {
|
|||||||
|
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
VersionVector deserializedVV;
|
VersionVector deserializedVV;
|
||||||
while (state.KeepRunning()) {
|
for (auto _ : state) {
|
||||||
size = dynamic_size_traits<VersionVector>::size(serializedVV, context);
|
size = dynamic_size_traits<VersionVector>::size(serializedVV, context);
|
||||||
|
|
||||||
uint8_t* buf = context.allocate(size);
|
uint8_t* buf = context.allocate(size);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user