Extract common functionalities
This commit is contained in:
parent
cceab46a7c
commit
41b06a0a37
@ -79,3 +79,6 @@ target_link_libraries(${test_prefix}data_structures_find mg-utils mg-storage-v3)
|
||||
|
||||
add_benchmark(data_structures_contains.cpp)
|
||||
target_link_libraries(${test_prefix}data_structures_contains mg-utils mg-storage-v3)
|
||||
|
||||
add_benchmark(data_structures_remove.cpp)
|
||||
target_link_libraries(${test_prefix}data_structures_contains mg-utils mg-storage-v3)
|
||||
|
76
tests/benchmark/data_structures_common.hpp
Normal file
76
tests/benchmark/data_structures_common.hpp
Normal file
@ -0,0 +1,76 @@
|
||||
// Copyright 2022 Memgraph Ltd.
|
||||
//
|
||||
// Use of this software is governed by the Business Source License
|
||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||
// License, and you may not use this file except in compliance with the Business Source License.
|
||||
//
|
||||
// As of the Change Date specified in that file, in accordance with
|
||||
// the Business Source License, use of this software will be governed
|
||||
// by the Apache License, Version 2.0, included in the file
|
||||
// licenses/APL.txt.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#include "btree_map.hpp"
|
||||
#include "coordinator/hybrid_logical_clock.hpp"
|
||||
#include "storage/v3/lexicographically_ordered_vertex.hpp"
|
||||
#include "storage/v3/mvcc.hpp"
|
||||
#include "storage/v3/transaction.hpp"
|
||||
#include "utils/skip_list.hpp"
|
||||
|
||||
namespace memgraph::benchmark {
|
||||
|
||||
template <typename T>
|
||||
inline void PrepareData(utils::SkipList<T> &skip_list, const int64_t num_elements) {
|
||||
coordinator::Hlc start_timestamp;
|
||||
storage::v3::IsolationLevel isolation_level{storage::v3::IsolationLevel::SNAPSHOT_ISOLATION};
|
||||
storage::v3::Transaction transaction{start_timestamp, isolation_level};
|
||||
auto *delta = storage::v3::CreateDeleteObjectDelta(&transaction);
|
||||
for (auto i{0}; i < num_elements; ++i) {
|
||||
auto acc = skip_list.access();
|
||||
acc.insert({storage::v3::Vertex(delta, std::vector<storage::v3::PropertyValue>{storage::v3::PropertyValue{i}})});
|
||||
}
|
||||
}
|
||||
|
||||
template <typename TKey, typename TValue>
|
||||
inline void PrepareData(std::map<TKey, TValue> &std_map, const int64_t num_elements) {
|
||||
coordinator::Hlc start_timestamp;
|
||||
storage::v3::IsolationLevel isolation_level{storage::v3::IsolationLevel::SNAPSHOT_ISOLATION};
|
||||
storage::v3::Transaction transaction{start_timestamp, isolation_level};
|
||||
auto *delta = storage::v3::CreateDeleteObjectDelta(&transaction);
|
||||
for (auto i{0}; i < num_elements; ++i) {
|
||||
std_map.insert({storage::v3::PrimaryKey{storage::v3::PropertyValue{i}},
|
||||
storage::v3::LexicographicallyOrderedVertex{storage::v3::Vertex{
|
||||
delta, std::vector<storage::v3::PropertyValue>{storage::v3::PropertyValue{i}}}}});
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void PrepareData(std::set<T> &std_set, const int64_t num_elements) {
|
||||
coordinator::Hlc start_timestamp;
|
||||
storage::v3::IsolationLevel isolation_level{storage::v3::IsolationLevel::SNAPSHOT_ISOLATION};
|
||||
storage::v3::Transaction transaction{start_timestamp, isolation_level};
|
||||
auto *delta = storage::v3::CreateDeleteObjectDelta(&transaction);
|
||||
for (auto i{0}; i < num_elements; ++i) {
|
||||
std_set.insert(storage::v3::LexicographicallyOrderedVertex{
|
||||
storage::v3::Vertex{delta, std::vector<storage::v3::PropertyValue>{storage::v3::PropertyValue{i}}}});
|
||||
}
|
||||
}
|
||||
|
||||
template <typename TKey, typename TValue>
|
||||
inline void PrepareData(tlx::btree_map<TKey, TValue> &bpp_tree, const int64_t num_elements) {
|
||||
coordinator::Hlc start_timestamp;
|
||||
storage::v3::IsolationLevel isolation_level{storage::v3::IsolationLevel::SNAPSHOT_ISOLATION};
|
||||
storage::v3::Transaction transaction{start_timestamp, isolation_level};
|
||||
auto *delta = storage::v3::CreateDeleteObjectDelta(&transaction);
|
||||
for (auto i{0}; i < num_elements; ++i) {
|
||||
bpp_tree.insert({storage::v3::PrimaryKey{storage::v3::PropertyValue{i}},
|
||||
storage::v3::LexicographicallyOrderedVertex{storage::v3::Vertex{
|
||||
delta, std::vector<storage::v3::PropertyValue>{storage::v3::PropertyValue{i}}}}});
|
||||
}
|
||||
}
|
||||
} // namespace memgraph::benchmark
|
131
tests/benchmark/data_structures_contains.cpp
Normal file
131
tests/benchmark/data_structures_contains.cpp
Normal file
@ -0,0 +1,131 @@
|
||||
// Copyright 2022 Memgraph Ltd.
|
||||
//
|
||||
// Use of this software is governed by the Business Source License
|
||||
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
|
||||
// License, and you may not use this file except in compliance with the Business Source License.
|
||||
//
|
||||
// As of the Change Date specified in that file, in accordance with
|
||||
// the Business Source License, use of this software will be governed
|
||||
// by the Apache License, Version 2.0, included in the file
|
||||
// licenses/APL.txt.
|
||||
|
||||
#include <atomic>
|
||||
#include <concepts>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <exception>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include <benchmark/benchmark.h>
|
||||
#include <gflags/gflags.h>
|
||||
|
||||
#include "btree_map.hpp"
|
||||
#include "data_structures_common.hpp"
|
||||
#include "storage/v3/key_store.hpp"
|
||||
#include "storage/v3/lexicographically_ordered_vertex.hpp"
|
||||
#include "storage/v3/mvcc.hpp"
|
||||
#include "storage/v3/property_value.hpp"
|
||||
#include "storage/v3/transaction.hpp"
|
||||
#include "storage/v3/vertex.hpp"
|
||||
#include "utils/skip_list.hpp"
|
||||
|
||||
namespace memgraph::benchmark {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Testing Contains Operation
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
static void BM_BenchmarkContainsSkipList(::benchmark::State &state) {
|
||||
utils::SkipList<storage::v3::LexicographicallyOrderedVertex> skip_list;
|
||||
PrepareData(skip_list, state.range(0));
|
||||
// So we can also have elements that does don't exist
|
||||
std::mt19937 i_generator(std::random_device{}());
|
||||
std::uniform_int_distribution<int64_t> i_distribution(0, state.range(0) * 2);
|
||||
int64_t found_elems{0};
|
||||
for (auto _ : state) {
|
||||
for (auto i{0}; i < state.range(0); ++i) {
|
||||
int64_t value = i_distribution(i_generator);
|
||||
auto acc = skip_list.access();
|
||||
if (acc.contains(storage::v3::PrimaryKey{{storage::v3::PropertyValue(value)}})) {
|
||||
found_elems++;
|
||||
}
|
||||
}
|
||||
}
|
||||
state.SetItemsProcessed(found_elems);
|
||||
}
|
||||
|
||||
static void BM_BenchmarkContainsStdMap(::benchmark::State &state) {
|
||||
std::map<storage::v3::PrimaryKey, storage::v3::LexicographicallyOrderedVertex> std_map;
|
||||
PrepareData(std_map, state.range(0));
|
||||
|
||||
// So we can also have elements that does don't exist
|
||||
std::mt19937 i_generator(std::random_device{}());
|
||||
std::uniform_int_distribution<int64_t> i_distribution(0, state.range(0) * 2);
|
||||
int64_t found_elems{0};
|
||||
for (auto _ : state) {
|
||||
for (auto i{0}; i < state.range(0); ++i) {
|
||||
int64_t value = i_distribution(i_generator);
|
||||
if (std_map.contains(storage::v3::PrimaryKey{{storage::v3::PropertyValue(value)}})) {
|
||||
found_elems++;
|
||||
}
|
||||
}
|
||||
}
|
||||
state.SetItemsProcessed(found_elems);
|
||||
}
|
||||
|
||||
static void BM_BenchmarkContainsStdSet(::benchmark::State &state) {
|
||||
std::set<storage::v3::LexicographicallyOrderedVertex> std_set;
|
||||
PrepareData(std_set, state.range(0));
|
||||
coordinator::Hlc start_timestamp;
|
||||
storage::v3::IsolationLevel isolation_level{storage::v3::IsolationLevel::SNAPSHOT_ISOLATION};
|
||||
storage::v3::Transaction transaction{start_timestamp, isolation_level};
|
||||
auto *delta = storage::v3::CreateDeleteObjectDelta(&transaction);
|
||||
// So we can also have elements that does don't exist
|
||||
std::mt19937 i_generator(std::random_device{}());
|
||||
std::uniform_int_distribution<int64_t> i_distribution(0, state.range(0) * 2);
|
||||
int64_t found_elems{0};
|
||||
for (auto _ : state) {
|
||||
for (auto i{0}; i < state.range(0); ++i) {
|
||||
int64_t value = i_distribution(i_generator);
|
||||
if (std_set.contains(storage::v3::LexicographicallyOrderedVertex{
|
||||
storage::v3::Vertex{delta, storage::v3::PrimaryKey{storage::v3::PropertyValue{value}}}})) {
|
||||
found_elems++;
|
||||
}
|
||||
}
|
||||
}
|
||||
state.SetItemsProcessed(found_elems);
|
||||
}
|
||||
|
||||
static void BM_BenchmarkContainsBppTree(::benchmark::State &state) {
|
||||
tlx::btree_map<storage::v3::PrimaryKey, storage::v3::LexicographicallyOrderedVertex> bpp_tree;
|
||||
PrepareData(bpp_tree, state.range(0));
|
||||
|
||||
// So we can also have elements that does don't exist
|
||||
std::mt19937 i_generator(std::random_device{}());
|
||||
std::uniform_int_distribution<int64_t> i_distribution(0, state.range(0) * 2);
|
||||
int64_t found_elems{0};
|
||||
for (auto _ : state) {
|
||||
for (auto i{0}; i < state.range(0); ++i) {
|
||||
int64_t value = i_distribution(i_generator);
|
||||
if (bpp_tree.count(storage::v3::PrimaryKey{{storage::v3::PropertyValue(value)}}) > 0) {
|
||||
found_elems++;
|
||||
}
|
||||
}
|
||||
}
|
||||
state.SetItemsProcessed(found_elems);
|
||||
}
|
||||
|
||||
BENCHMARK(BM_BenchmarkContainsSkipList)->Arg(1000);
|
||||
|
||||
BENCHMARK(BM_BenchmarkContainsStdMap)->Arg(1000);
|
||||
|
||||
BENCHMARK(BM_BenchmarkContainsStdSet)->Arg(1000);
|
||||
|
||||
BENCHMARK(BM_BenchmarkContainsBppTree)->Arg(1000);
|
||||
|
||||
} // namespace memgraph::benchmark
|
||||
|
||||
BENCHMARK_MAIN();
|
@ -24,7 +24,7 @@
|
||||
#include <gflags/gflags.h>
|
||||
|
||||
#include "btree_map.hpp"
|
||||
#include "skip_list_common.hpp"
|
||||
#include "data_structures_common.hpp"
|
||||
#include "storage/v3/key_store.hpp"
|
||||
#include "storage/v3/lexicographically_ordered_vertex.hpp"
|
||||
#include "storage/v3/mvcc.hpp"
|
||||
@ -40,14 +40,7 @@ namespace memgraph::benchmark {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
static void BM_BenchmarkFindSkipList(::benchmark::State &state) {
|
||||
utils::SkipList<storage::v3::LexicographicallyOrderedVertex> skip_list;
|
||||
coordinator::Hlc start_timestamp;
|
||||
storage::v3::IsolationLevel isolation_level{storage::v3::IsolationLevel::SNAPSHOT_ISOLATION};
|
||||
storage::v3::Transaction transaction{start_timestamp, isolation_level};
|
||||
auto *delta = storage::v3::CreateDeleteObjectDelta(&transaction);
|
||||
for (auto i{0}; i < state.range(0); ++i) {
|
||||
auto acc = skip_list.access();
|
||||
acc.insert({storage::v3::Vertex(delta, std::vector<storage::v3::PropertyValue>{storage::v3::PropertyValue{i}})});
|
||||
}
|
||||
PrepareData(skip_list, state.range(0));
|
||||
// So we can also have elements that does don't exist
|
||||
std::mt19937 i_generator(std::random_device{}());
|
||||
std::uniform_int_distribution<int64_t> i_distribution(0, state.range(0) * 2);
|
||||
@ -66,15 +59,7 @@ static void BM_BenchmarkFindSkipList(::benchmark::State &state) {
|
||||
|
||||
static void BM_BenchmarkFindStdMap(::benchmark::State &state) {
|
||||
std::map<storage::v3::PrimaryKey, storage::v3::LexicographicallyOrderedVertex> std_map;
|
||||
coordinator::Hlc start_timestamp;
|
||||
storage::v3::IsolationLevel isolation_level{storage::v3::IsolationLevel::SNAPSHOT_ISOLATION};
|
||||
storage::v3::Transaction transaction{start_timestamp, isolation_level};
|
||||
auto *delta = storage::v3::CreateDeleteObjectDelta(&transaction);
|
||||
for (auto i{0}; i < state.range(0); ++i) {
|
||||
std_map.insert({storage::v3::PrimaryKey{storage::v3::PropertyValue{i}},
|
||||
storage::v3::LexicographicallyOrderedVertex{storage::v3::Vertex{
|
||||
delta, std::vector<storage::v3::PropertyValue>{storage::v3::PropertyValue{i}}}}});
|
||||
}
|
||||
PrepareData(std_map, state.range(0));
|
||||
// So we can also have elements that does don't exist
|
||||
std::mt19937 i_generator(std::random_device{}());
|
||||
std::uniform_int_distribution<int64_t> i_distribution(0, state.range(0) * 2);
|
||||
@ -92,14 +77,12 @@ static void BM_BenchmarkFindStdMap(::benchmark::State &state) {
|
||||
|
||||
static void BM_BenchmarkFindStdSet(::benchmark::State &state) {
|
||||
std::set<storage::v3::LexicographicallyOrderedVertex> std_set;
|
||||
PrepareData(std_set, state.range(0));
|
||||
coordinator::Hlc start_timestamp;
|
||||
storage::v3::IsolationLevel isolation_level{storage::v3::IsolationLevel::SNAPSHOT_ISOLATION};
|
||||
storage::v3::Transaction transaction{start_timestamp, isolation_level};
|
||||
auto *delta = storage::v3::CreateDeleteObjectDelta(&transaction);
|
||||
for (auto i{0}; i < state.range(0); ++i) {
|
||||
std_set.insert(storage::v3::LexicographicallyOrderedVertex{
|
||||
storage::v3::Vertex{delta, std::vector<storage::v3::PropertyValue>{storage::v3::PropertyValue{i}}}});
|
||||
}
|
||||
|
||||
// So we can also have elements that does don't exist
|
||||
std::mt19937 i_generator(std::random_device{}());
|
||||
std::uniform_int_distribution<int64_t> i_distribution(0, state.range(0) * 2);
|
||||
@ -118,15 +101,7 @@ static void BM_BenchmarkFindStdSet(::benchmark::State &state) {
|
||||
|
||||
static void BM_BenchmarkFindBppTree(::benchmark::State &state) {
|
||||
tlx::btree_map<storage::v3::PrimaryKey, storage::v3::LexicographicallyOrderedVertex> bpp_tree;
|
||||
coordinator::Hlc start_timestamp;
|
||||
storage::v3::IsolationLevel isolation_level{storage::v3::IsolationLevel::SNAPSHOT_ISOLATION};
|
||||
storage::v3::Transaction transaction{start_timestamp, isolation_level};
|
||||
auto *delta = storage::v3::CreateDeleteObjectDelta(&transaction);
|
||||
for (auto i{0}; i < state.range(0); ++i) {
|
||||
bpp_tree.insert({storage::v3::PrimaryKey{storage::v3::PropertyValue{i}},
|
||||
storage::v3::LexicographicallyOrderedVertex{storage::v3::Vertex{
|
||||
delta, std::vector<storage::v3::PropertyValue>{storage::v3::PropertyValue{i}}}}});
|
||||
}
|
||||
PrepareData(bpp_tree, state.range(0));
|
||||
// So we can also have elements that does don't exist
|
||||
std::mt19937 i_generator(std::random_device{}());
|
||||
std::uniform_int_distribution<int64_t> i_distribution(0, state.range(0) * 2);
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include <gflags/gflags.h>
|
||||
|
||||
#include "btree_map.hpp"
|
||||
#include "skip_list_common.hpp"
|
||||
#include "storage/v3/key_store.hpp"
|
||||
#include "storage/v3/lexicographically_ordered_vertex.hpp"
|
||||
#include "storage/v3/mvcc.hpp"
|
||||
|
Loading…
Reference in New Issue
Block a user