Added BenchIterate microbenchmark
This commit is contained in:
parent
92b2894311
commit
a5cb894e56
|
@ -0,0 +1,64 @@
|
|||
/*
|
||||
* BenchIterate.cpp
|
||||
*
|
||||
* This source file is part of the FoundationDB open source project
|
||||
*
|
||||
* Copyright 2013-2020 Apple Inc. and the FoundationDB project authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "benchmark/benchmark.h"
|
||||
|
||||
#include "fdbbench/GlobalData.h"
|
||||
#include "fdbclient/CommitTransaction.h"
|
||||
#include "fdbclient/FDBTypes.h"
|
||||
#include "fdbclient/MutationList.h"
|
||||
#include "flow/Arena.h"
|
||||
#include "flow/FastAlloc.h"
|
||||
|
||||
void populate(Standalone<VectorRef<MutationRef>>& mutations, size_t items, size_t size, KeyRef key, ValueRef value) {
|
||||
mutations = Standalone<VectorRef<MutationRef>>{};
|
||||
mutations.reserve(mutations.arena(), items);
|
||||
for (int i = 0; i < size; ++i) {
|
||||
mutations.emplace_back_deep(mutations.arena(), MutationRef::Type::SetValue, key, value);
|
||||
}
|
||||
}
|
||||
|
||||
void populate(MutationList& mutations, size_t items, size_t size, KeyRef key, ValueRef value) {
|
||||
mutations = MutationList{};
|
||||
for (int i = 0; i < size; ++i) {
|
||||
mutations.push_back_deep(mutations.arena(), MutationRef(MutationRef::Type::SetValue, key, value));
|
||||
}
|
||||
}
|
||||
|
||||
// Benchmarks iteration over a list of mutations
|
||||
template <class ListImpl>
|
||||
static void bench_iterate(benchmark::State& state) {
|
||||
size_t items = state.range(0);
|
||||
size_t size = state.range(1);
|
||||
auto kv = getKV(size, size);
|
||||
ListImpl mutations;
|
||||
populate(mutations, items, size, kv.key, kv.value);
|
||||
while (state.KeepRunning()) {
|
||||
for (const auto& mutation : mutations) {
|
||||
benchmark::DoNotOptimize(mutation);
|
||||
}
|
||||
}
|
||||
state.SetItemsProcessed(items * static_cast<long>(state.iterations()));
|
||||
}
|
||||
|
||||
BENCHMARK_TEMPLATE(bench_iterate, Standalone<VectorRef<MutationRef>>)
|
||||
->Ranges({ { 1, 1 << 20 }, { 1, 1 << 9 } })
|
||||
->ReportAggregatesOnly(true);
|
||||
BENCHMARK_TEMPLATE(bench_iterate, MutationList)->Ranges({ { 1, 1 << 20 }, { 1, 1 << 9 } })->ReportAggregatesOnly(true);
|
|
@ -20,28 +20,29 @@
|
|||
|
||||
#include "benchmark/benchmark.h"
|
||||
|
||||
#include "fdbbench/GlobalData.h"
|
||||
#include "fdbclient/CommitTransaction.h"
|
||||
#include "fdbclient/FDBTypes.h"
|
||||
#include "flow/Arena.h"
|
||||
#include "flow/FastAlloc.h"
|
||||
|
||||
constexpr const uint8_t data[1024] = {};
|
||||
static constexpr bool EMPLACE_BACK = true;
|
||||
static constexpr bool PUSH_BACK = false;
|
||||
|
||||
// Benchmarks the population of a VectorRef<MutationRef>
|
||||
template <bool emplace>
|
||||
static void bench_populate(benchmark::State& state) {
|
||||
int items = state.range(0);
|
||||
size_t items = state.range(0);
|
||||
size_t size = state.range(1);
|
||||
KeyRef key(data, size);
|
||||
KeyRef value(data + size, size);
|
||||
auto kv = getKV(size, size);
|
||||
while (state.KeepRunning()) {
|
||||
Standalone<VectorRef<MutationRef>> mutations;
|
||||
mutations.reserve(mutations.arena(), items);
|
||||
for (int i = 0; i < items; ++i) {
|
||||
if constexpr (emplace) {
|
||||
mutations.emplace_back(mutations.arena(), MutationRef::Type::SetValue, key, value);
|
||||
mutations.emplace_back_deep(mutations.arena(), MutationRef::Type::SetValue, kv.key, kv.value);
|
||||
} else {
|
||||
mutations.push_back(mutations.arena(), MutationRef(MutationRef::Type::SetValue, key, value));
|
||||
mutations.push_back_deep(mutations.arena(), MutationRef(MutationRef::Type::SetValue, kv.key, kv.value));
|
||||
}
|
||||
}
|
||||
benchmark::DoNotOptimize(mutations);
|
||||
|
@ -49,13 +50,5 @@ static void bench_populate(benchmark::State& state) {
|
|||
state.SetItemsProcessed(items * static_cast<long>(state.iterations()));
|
||||
}
|
||||
|
||||
static void populate_emplace(benchmark::State& state) {
|
||||
bench_populate<true>(state);
|
||||
}
|
||||
|
||||
static void populate_push(benchmark::State& state) {
|
||||
bench_populate<false>(state);
|
||||
}
|
||||
|
||||
BENCHMARK(populate_emplace)->Ranges({ { 1, 1 << 20 }, { 1, 512 } })->ReportAggregatesOnly(true);
|
||||
BENCHMARK(populate_push)->Ranges({ { 1, 1 << 20 }, { 1, 512 } })->ReportAggregatesOnly(true);
|
||||
BENCHMARK_TEMPLATE(bench_populate, EMPLACE_BACK)->Ranges({ { 1, 1 << 20 }, { 1, 512 } })->ReportAggregatesOnly(true);
|
||||
BENCHMARK_TEMPLATE(bench_populate, PUSH_BACK)->Ranges({ { 1, 1 << 20 }, { 1, 512 } })->ReportAggregatesOnly(true);
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
set(FDBBENCH_SRCS
|
||||
bench.cpp
|
||||
BenchPopulate.cpp)
|
||||
fdbbench.cpp
|
||||
BenchIterate.cpp
|
||||
BenchPopulate.cpp
|
||||
GlobalData.h)
|
||||
|
||||
project (fdbbench)
|
||||
# include the configurations from benchmark.cmake
|
||||
|
@ -32,6 +34,4 @@ add_subdirectory(
|
|||
)
|
||||
include_directories(${CMAKE_CURRENT_BINARY_DIR}/googlebenchmark-src/include)
|
||||
add_executable(fdbbench ${FDBBENCH_SRCS})
|
||||
target_link_libraries(fdbbench benchmark)
|
||||
target_link_libraries(fdbbench pthread)
|
||||
target_link_libraries(fdbbench flow)
|
||||
target_link_libraries(fdbbench benchmark pthread flow)
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* GlobalData.h
|
||||
*
|
||||
* This source file is part of the FoundationDB open source project
|
||||
*
|
||||
* Copyright 2013-2020 Apple Inc. and the FoundationDB project authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __FDBBENCH_GLOBALDATA_H__
|
||||
#define __FDBBENCH_GLOBALDATA_H__
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "fdbclient/FDBTypes.h"
|
||||
|
||||
inline KeyValueRef getKV(size_t keySize, size_t valueSize) {
|
||||
static constexpr size_t globalDataSize = 1024;
|
||||
static const uint8_t* globalData = nullptr;
|
||||
if (!globalData) {
|
||||
globalData = static_cast<const uint8_t*>(allocateFast(globalDataSize));
|
||||
}
|
||||
ASSERT(keySize + valueSize <= globalDataSize);
|
||||
return KeyValueRef(KeyRef(globalData, keySize), ValueRef(globalData + keySize, valueSize));
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* bench.cpp
|
||||
* fdbbench.cpp
|
||||
*
|
||||
* This source file is part of the FoundationDB open source project
|
||||
*
|
Loading…
Reference in New Issue