2020-06-23 13:07:22 +08:00
|
|
|
/*
|
|
|
|
* BenchPopulate.cpp
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
2022-03-22 04:36:23 +08:00
|
|
|
* Copyright 2013-2022 Apple Inc. and the FoundationDB project authors
|
2020-06-23 13:07:22 +08:00
|
|
|
*
|
|
|
|
* 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 "fdbclient/CommitTransaction.h"
|
|
|
|
#include "fdbclient/FDBTypes.h"
|
|
|
|
#include "flow/Arena.h"
|
|
|
|
#include "flow/FastAlloc.h"
|
2020-08-04 06:10:31 +08:00
|
|
|
#include "flowbench/GlobalData.h"
|
2020-06-23 13:07:22 +08:00
|
|
|
|
2020-07-27 05:26:23 +08:00
|
|
|
static constexpr bool EMPLACE_BACK = true;
|
|
|
|
static constexpr bool PUSH_BACK = false;
|
2020-06-23 13:07:22 +08:00
|
|
|
|
|
|
|
// Benchmarks the population of a VectorRef<MutationRef>
|
|
|
|
template <bool emplace>
|
|
|
|
static void bench_populate(benchmark::State& state) {
|
2020-07-27 05:26:23 +08:00
|
|
|
size_t items = state.range(0);
|
2020-06-23 13:07:22 +08:00
|
|
|
size_t size = state.range(1);
|
2020-07-27 05:26:23 +08:00
|
|
|
auto kv = getKV(size, size);
|
2020-06-23 13:07:22 +08:00
|
|
|
while (state.KeepRunning()) {
|
|
|
|
Standalone<VectorRef<MutationRef>> mutations;
|
|
|
|
mutations.reserve(mutations.arena(), items);
|
|
|
|
for (int i = 0; i < items; ++i) {
|
|
|
|
if constexpr (emplace) {
|
2020-07-27 05:26:23 +08:00
|
|
|
mutations.emplace_back_deep(mutations.arena(), MutationRef::Type::SetValue, kv.key, kv.value);
|
2020-06-23 13:07:22 +08:00
|
|
|
} else {
|
2020-07-27 05:26:23 +08:00
|
|
|
mutations.push_back_deep(mutations.arena(), MutationRef(MutationRef::Type::SetValue, kv.key, kv.value));
|
2020-06-23 13:07:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
benchmark::DoNotOptimize(mutations);
|
|
|
|
}
|
|
|
|
state.SetItemsProcessed(items * static_cast<long>(state.iterations()));
|
|
|
|
}
|
|
|
|
|
2020-07-27 05:26:23 +08:00
|
|
|
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);
|