From bbd6f91e5fafd7f9180edd571a5be843023ef3be Mon Sep 17 00:00:00 2001 From: sale Date: Tue, 22 Nov 2016 10:24:20 +0000 Subject: [PATCH] Added benchmark test for QueryStripper; Fixed timer bug Summary: Added benchmark for QueryStripper; Fixed Timer bug; Test Plan: manual Reviewers: buda Subscribers: buda Maniphest Tasks: T100 Differential Revision: https://memgraph.phacility.com/D5 --- include/utils/time/timer.hpp | 1 + tests/benchmark/CMakeLists.txt | 4 ++ tests/benchmark/stripper.cpp | 44 +++++++++++++++++++ .../cypher_queries/stripper/query_dict.yaml | 42 ++++++++++++++++++ 4 files changed, 91 insertions(+) create mode 100644 tests/benchmark/stripper.cpp create mode 100644 tests/data/cypher_queries/stripper/query_dict.yaml diff --git a/include/utils/time/timer.hpp b/include/utils/time/timer.hpp index e8332c5b3..e989ba600 100644 --- a/include/utils/time/timer.hpp +++ b/include/utils/time/timer.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include diff --git a/tests/benchmark/CMakeLists.txt b/tests/benchmark/CMakeLists.txt index ef94ffd2c..a30271887 100644 --- a/tests/benchmark/CMakeLists.txt +++ b/tests/benchmark/CMakeLists.txt @@ -12,6 +12,10 @@ foreach(ONE_BENCH_CPP ${ALL_BENCH_CPP}) add_executable(${TARGET_NAME} ${ONE_BENCH_CPP}) set_target_properties(${TARGET_NAME} PROPERTIES OUTPUT_NAME ${ONE_BENCH_EXEC}) target_link_libraries(${TARGET_NAME} benchmark ${CMAKE_THREAD_LIBS_INIT}) + target_link_libraries(${TARGET_NAME} memgraph) + target_link_libraries(${TARGET_NAME} ${fmt_static_lib}) + target_link_libraries(${TARGET_NAME} Threads::Threads) + target_link_libraries(${TARGET_NAME} ${yaml_static_lib}) add_test(${TARGET_NAME} ${ONE_BENCH_EXEC}) endforeach() diff --git a/tests/benchmark/stripper.cpp b/tests/benchmark/stripper.cpp new file mode 100644 index 000000000..9a9caffb9 --- /dev/null +++ b/tests/benchmark/stripper.cpp @@ -0,0 +1,44 @@ +#include "logging/default.hpp" +#include "logging/streams/stdout.hpp" +#include "utils/time/timer.hpp" +#include "query/preprocesor.hpp" + +#include "benchmark/benchmark_api.h" +#include "yaml-cpp/yaml.h" + +auto BM_Strip = [](benchmark::State& state, auto& function, std::string query) { + while (state.KeepRunning()) { + for (int start = 0; start < state.range(0); start++) { + function(query); + } + } + state.SetComplexityN(state.range(0)); +}; + +int main(int argc, char** argv) { + logging::init_async(); + logging::log->pipe(std::make_unique()); + + YAML::Node dataset = YAML::LoadFile( + "../../tests/data/cypher_queries/stripper/query_dict.yaml"); + + QueryPreprocessor processor; + using std::placeholders::_1; + std::function preprocess = + std::bind(&QueryPreprocessor::preprocess, &processor, _1); + + auto tests = dataset["benchmark_queries"].as>(); + for (auto& test : tests) { + auto* benchmark = + benchmark::RegisterBenchmark(test.c_str(), BM_Strip, preprocess, test) + ->RangeMultiplier(2) + ->Range(1, 8 << 10) + ->Complexity(benchmark::oN); + ; + } + + benchmark::Initialize(&argc, argv); + benchmark::RunSpecifiedBenchmarks(); + + return 0; +} diff --git a/tests/data/cypher_queries/stripper/query_dict.yaml b/tests/data/cypher_queries/stripper/query_dict.yaml new file mode 100644 index 000000000..549733ce4 --- /dev/null +++ b/tests/data/cypher_queries/stripper/query_dict.yaml @@ -0,0 +1,42 @@ +benchmark_queries: + - "MATCH (a) RETURN size(collect(a))" + + - "CREATE (a:L), (b1), (b2) CREATE (a)-[:A]->(b1), (a)-[:A]->(b2)" + + - "MATCH (a:L)-[rel]->(b) RETURN a, count(*)" + + - "CREATE ({division: 'Sweden'})" + + - "MATCH (n) RETURN n.division, count(*) ORDER BY count(*) DESC, n.division ASC" + + - "UNWIND ['a', 'b', 'B', null, 'abc', 'abc1'] AS i RETURN max(i)" + + - "CREATE ({created: true})" + + - "MATCH (a)-[r]-(b) DELETE r, a, b RETURN count(*) AS c" + + - "MATCH (u:User) WITH {key: u} AS nodes DELETE nodes.key" + + - "CREATE ()-[:T {id: 42, alive: true, name: kifla, height=4.2}]->()" + + - "MATCH p = ()-[r:T]-() WHERE r.id = 42 DELETE r" + + - "UNWIND range(0, 1000) AS i CREATE (:A {id: i}) MERGE (:B {id: i % 10})" + + - "MATCH (n) WHERE NOT(n.name = 'apa' AND false) RETURN n" + + - "CREATE ()-[:REL {property1: 12, property2: 24}]->()" + + - "MATCH (n:A) WHERE n.name = 'Andres' SET n.name = 'Michael' RETURN n" + + - "MATCH (n:A) SET (n).name = 'memgraph' RETURN n" + + - "CREATE (a {foo: [1, 2, 3]}) SET a.foo = a.foo + [4, 5] RETURN a.foo" + + - "MATCH (n:X {foo: 'A'}) SET n = {foo: 'B', baz: 'C'} RETURN n" + + - "MATCH (n:X {foo: 'A'}) SET n += {foo: null} RETURN n" + + - "MATCH (n) WITH n LIMIT toInteger(ceil(1.7)) RETURN count(*) AS count" + + - "MATCH (a:A), (b:B) MERGE (a)-[r:TYPE]->(b) ON CREATE SET r.name = 'Lola' RETURN count(r)"