2021-10-26 14:53:56 +08:00
|
|
|
// Copyright 2021 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.
|
|
|
|
|
2019-06-07 20:31:25 +08:00
|
|
|
#include <benchmark/benchmark.h>
|
|
|
|
|
2019-09-11 22:10:53 +08:00
|
|
|
#include "query/db_accessor.hpp"
|
2019-06-07 20:31:25 +08:00
|
|
|
#include "query/interpret/eval.hpp"
|
2019-10-10 17:23:33 +08:00
|
|
|
#include "query/interpreter.hpp"
|
2019-11-22 00:24:01 +08:00
|
|
|
#include "storage/v2/storage.hpp"
|
2019-06-07 20:31:25 +08:00
|
|
|
|
|
|
|
// The following classes are wrappers for utils::MemoryResource, so that we can
|
|
|
|
// use BENCHMARK_TEMPLATE
|
|
|
|
|
|
|
|
class MonotonicBufferResource final {
|
|
|
|
utils::MonotonicBufferResource memory_{query::kExecutionMemoryBlockSize};
|
|
|
|
|
|
|
|
public:
|
|
|
|
utils::MemoryResource *get() { return &memory_; }
|
|
|
|
};
|
|
|
|
|
|
|
|
class NewDeleteResource final {
|
|
|
|
public:
|
|
|
|
utils::MemoryResource *get() { return utils::NewDeleteResource(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class TMemory>
|
|
|
|
// NOLINTNEXTLINE(google-runtime-references)
|
|
|
|
static void MapLiteral(benchmark::State &state) {
|
|
|
|
query::AstStorage ast;
|
|
|
|
query::SymbolTable symbol_table;
|
|
|
|
TMemory memory;
|
2019-06-17 19:39:40 +08:00
|
|
|
query::Frame frame(symbol_table.max_position(), memory.get());
|
2019-11-22 00:24:01 +08:00
|
|
|
storage::Storage db;
|
|
|
|
auto storage_dba = db.Access();
|
|
|
|
query::DbAccessor dba(&storage_dba);
|
2019-06-07 20:31:25 +08:00
|
|
|
std::unordered_map<query::PropertyIx, query::Expression *> elements;
|
|
|
|
for (int64_t i = 0; i < state.range(0); ++i) {
|
2021-02-18 22:32:43 +08:00
|
|
|
elements.emplace(ast.GetPropertyIx("prop" + std::to_string(i)), ast.Create<query::PrimitiveLiteral>(i));
|
2019-06-07 20:31:25 +08:00
|
|
|
}
|
|
|
|
auto *expr = ast.Create<query::MapLiteral>(elements);
|
|
|
|
query::EvaluationContext evaluation_context{memory.get()};
|
2021-02-18 22:32:43 +08:00
|
|
|
evaluation_context.properties = query::NamesToProperties(ast.properties_, &dba);
|
|
|
|
query::ExpressionEvaluator evaluator(&frame, symbol_table, evaluation_context, &dba, storage::View::NEW);
|
2019-06-07 20:31:25 +08:00
|
|
|
while (state.KeepRunning()) {
|
|
|
|
benchmark::DoNotOptimize(expr->Accept(evaluator));
|
|
|
|
}
|
|
|
|
state.SetItemsProcessed(state.iterations());
|
|
|
|
}
|
|
|
|
|
2021-02-18 22:32:43 +08:00
|
|
|
BENCHMARK_TEMPLATE(MapLiteral, NewDeleteResource)->Range(512, 1U << 15U)->Unit(benchmark::kMicrosecond);
|
2019-06-07 20:31:25 +08:00
|
|
|
|
2021-02-18 22:32:43 +08:00
|
|
|
BENCHMARK_TEMPLATE(MapLiteral, MonotonicBufferResource)->Range(512, 1U << 15U)->Unit(benchmark::kMicrosecond);
|
2019-06-07 20:31:25 +08:00
|
|
|
|
|
|
|
template <class TMemory>
|
|
|
|
// NOLINTNEXTLINE(google-runtime-references)
|
|
|
|
static void AdditionOperator(benchmark::State &state) {
|
|
|
|
query::AstStorage ast;
|
|
|
|
query::SymbolTable symbol_table;
|
|
|
|
TMemory memory;
|
2019-06-17 19:39:40 +08:00
|
|
|
query::Frame frame(symbol_table.max_position(), memory.get());
|
2019-11-22 00:24:01 +08:00
|
|
|
storage::Storage db;
|
|
|
|
auto storage_dba = db.Access();
|
|
|
|
query::DbAccessor dba(&storage_dba);
|
2019-06-07 20:31:25 +08:00
|
|
|
query::Expression *expr = ast.Create<query::PrimitiveLiteral>(0);
|
|
|
|
for (int64_t i = 0; i < state.range(0); ++i) {
|
2021-02-18 22:32:43 +08:00
|
|
|
expr = ast.Create<query::AdditionOperator>(expr, ast.Create<query::PrimitiveLiteral>(i));
|
2019-06-07 20:31:25 +08:00
|
|
|
}
|
|
|
|
query::EvaluationContext evaluation_context{memory.get()};
|
2021-02-18 22:32:43 +08:00
|
|
|
query::ExpressionEvaluator evaluator(&frame, symbol_table, evaluation_context, &dba, storage::View::NEW);
|
2019-06-07 20:31:25 +08:00
|
|
|
while (state.KeepRunning()) {
|
|
|
|
benchmark::DoNotOptimize(expr->Accept(evaluator));
|
|
|
|
}
|
|
|
|
state.SetItemsProcessed(state.iterations());
|
|
|
|
}
|
|
|
|
|
2021-02-18 22:32:43 +08:00
|
|
|
BENCHMARK_TEMPLATE(AdditionOperator, NewDeleteResource)->Range(1024, 1U << 15U)->Unit(benchmark::kMicrosecond);
|
2019-06-07 20:31:25 +08:00
|
|
|
|
2021-02-18 22:32:43 +08:00
|
|
|
BENCHMARK_TEMPLATE(AdditionOperator, MonotonicBufferResource)->Range(1024, 1U << 15U)->Unit(benchmark::kMicrosecond);
|
2019-06-07 20:31:25 +08:00
|
|
|
|
|
|
|
BENCHMARK_MAIN();
|