google benchmark support

This commit is contained in:
Marko Budiselic 2016-11-18 17:35:29 +01:00
parent 29dbf43aa2
commit e1e345ccbb
18 changed files with 159 additions and 144 deletions

View File

@ -7,6 +7,10 @@ string(REPLACE " " "_" ProjectId ${ProjectId})
# set project name
project(${ProjectId})
# setup CMake module path, defines path for include() and find_package()
# https://cmake.org/cmake/help/latest/variable/CMAKE_MODULE_PATH.html
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
find_package(Threads REQUIRED)
# flags
@ -83,20 +87,12 @@ set(fmt_static_lib ${fmt_source_dir}/fmt/libfmt.a)
# yaml-cpp
set(yaml_source_dir ${libs_dir}/yaml-cpp)
set(yaml_static_lib ${yaml_source_dir}/libyaml-cpp.a)
# r3
set(r3_source_dir ${libs_dir}/r3)
set(r3_static_lib ${r3_source_dir}/.libs/libr3.a)
# http-parser
set(http_parser_source_dir "${libs_dir}/http-parser")
set(http_parser_static_lib ${http_parser_source_dir}/libhttp_parser.a)
# libuv
set(libuv_source_dir ${libs_dir}/libuv)
set(libuv_static_lib ${libuv_source_dir}/.libs/libuv.a)
# rapidjson (C++ JSON encoder/decoder)
set(rapidjson_source_dir "${libs_dir}/rapidjson")
# Catch (C++ Automated Test Cases in Headers)
set(catch_source_dir "${libs_dir}/Catch")
# load cmake modules: cmake/*.cmake
include(gbenchmark)
# build memgraph's cypher grammar
# copy grammar file to the build directory
FILE(COPY ${include_dir}/query/language/cypher/cypher.y DESTINATION ${CMAKE_BINARY_DIR})
@ -557,7 +553,7 @@ endif()
# benchmark binaries
if (BENCHMARK)
add_subdirectory(benchmark)
add_subdirectory(${PROJECT_SOURCE_DIR}/tests/benchmark)
endif()
# memgraph build name

View File

@ -1,21 +0,0 @@
CXX=clang++
CFLAGS=-std=c++1y -DNDEBUG -O2 -Wall -Wno-unknown-pragmas
CFLAGS_DEBUG=-std=c++1y -Wall -Wno-unknown-pragmas -g
LDFLAGS=-luv -lhttp_parser src/speedy/r3/.libs/libr3.a -L/usr/local/lib -lpcre -pthread
INC=-I./src/ -I./src/speedy/ -I./src/speedy/rapidjson/include/ -I./libs/lexertl
SOURCES=src/memgraph.cpp
EXECUTABLE=build/memgraph
all: $(EXECUTABLE)
$(EXECUTABLE): $(SOURCES)
$(CXX) $(CFLAGS) $(SOURCES) -o $(EXECUTABLE) $(INC) $(LDFLAGS)
debug: $(SOURCES)
$(CXX) $(CFLAGS_DEBUG) $(SOURCES) -o $(EXECUTABLE) $(INC) $(LDFLAGS)
.PHONY:
clean:
rm -f memgraph
rm -f *.o

View File

@ -1,8 +0,0 @@
cmake_minimum_required(VERSION 3.1)
project(memgraph_benchmark)
add_executable(skiplist_benchmark skiplist.cpp)
target_link_libraries(skiplist_benchmark Threads::Threads)
target_link_libraries(skiplist_benchmark memgraph)
target_link_libraries(skiplist_benchmark ${fmt_static_lib})

View File

@ -1,29 +0,0 @@
#include <iostream>
#include "data_structures/concurrent/skiplist.hpp"
#include "utils/time/timer.hpp"
int main(void)
{
SkipList<int> skiplist;
// insert a bunch of elements
{
int iters_no = 1000000;
auto skiplist_accessor = skiplist.access();
Stopwatch sw;
sw.Start();
for (int i = 0; i < iters_no; ++i)
{
skiplist_accessor.insert(std::move(i));
}
std::cout << "Skiplist contains: "
<< skiplist_accessor.size()
<< " elements"
<< std::endl;
}
return 0;
}

View File

@ -1,20 +0,0 @@
#!/bin/bash
while [[ $# > 1 ]]
do
key="$1"
case $key in
-t|--target)
target="$2"
shift
;;
esac
shift
done
if [[ -z $target ]]; then
target="all"
fi
cd src/api && python link_resources.py && cd ../..
make clean && make $target

1
cmake/DownloadProject Submodule

@ -0,0 +1 @@
Subproject commit bbc6bef03d194cf75492ef4881156f472cb78858

18
cmake/gbenchmark.cmake Normal file
View File

@ -0,0 +1,18 @@
if (CMAKE_VERSION VERSION_LESS 3.2)
set(UPDATE_DISCONNECTED_IF_AVAILABLE "")
else()
set(UPDATE_DISCONNECTED_IF_AVAILABLE "UPDATE_DISCONNECTED 1")
endif()
include(DownloadProject/DownloadProject)
download_project(
PROJ googlebenchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG master
${UPDATE_DISCONNECTED_IF_AVAILABLE}
)
add_subdirectory(${googlebenchmark_SOURCE_DIR} ${googlebenchmark_BINARY_DIR})
include_directories("${googlebenchmark_SOURCE_DIR}/include")

8
cmake/setup.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
# DownloadProject
git clone https://github.com/Crascit/DownloadProject
download_project_tag="master"
cd DownloadProject
git checkout ${download_project_tag}
cd ..

1
docs/index.md Normal file
View File

@ -0,0 +1 @@
# TODO

23
init.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
if ! type "wget" > /dev/null; then
echo >&2 "Please install wget or set it in your path. Aborting."; exit 1;
fi
if ! type "git" > /dev/null; then
echo >&2 "Please install git or set it in your path. Aborting."; exit 1;
fi
if ! type "cmake" > /dev/null; then
echo >&2 "Please install cmake or set it in your path. Aborting."; exit 1;
fi
cd cmake
./setup.sh
cd ..
cd libs
./setup.sh
cd ..
echo "DONE"

View File

@ -25,14 +25,6 @@ cmake .
make
cd ..
# http_parser
git clone https://github.com/nodejs/http-parser
http_parser_tag="4e382f96e6d3321538a78f2c7f9506d4e79b08d6"
cd http-parser
git checkout ${http_parser_tag}
make package
cd ..
# lemon
mkdir lemon
cd lemon
@ -49,33 +41,3 @@ lexertl_tag=7d4d36a357027df0e817453cc9cf948f71047ca9
cd lexertl
git checkout ${lexertl_tag}
cd ..
# libuv
git clone https://github.com/libuv/libuv.git
libuv_tag="c82eedd0a76233f0894098853b5a0c307af27064"
cd libuv
git checkout ${libuv_tag}
./autogen.sh && ./configure && make
cd ..
# rapidjson
git clone https://github.com/miloyip/rapidjson.git
rapidjson_tag=${3d5848a7cd3367c5cb451c6493165b7745948308}
cd rapidjson
git checkout ${rapidjson_tag}
cd ..
# r3
# UBUNTU 16.04
# TODO: automate this
# sudo apt-get -y install check libpcre3 libpcre3-dev libjemalloc-dev
# sudo apt-get -y install libjemalloc1 build-essential libtool automake
# sudo apt-get -y install autoconf pkg-config
git clone https://github.com/c9s/r3.git
r3_tag=28726b27af3cd0a9d3166033c6619a9c7227cb48
cd r3
git checkout ${r3_tag}
./autogen.sh && ./configure && make
cd ..

View File

@ -4,7 +4,9 @@
#include <unistd.h>
#include <unordered_map>
// TODO: remove barrier
#include "barrier/barrier.cpp"
#include "database/db.hpp"
#include "database/db_accessor.hpp"
#include "communication/bolt/v1/serialization/bolt_serializer.hpp"

View File

@ -3,7 +3,7 @@
#include <string>
#include <vector>
#include "query_engine/i_code_cpu.hpp"
#include "query/i_code_cpu.hpp"
#include "storage/model/properties/all.hpp"
#include "utils/memory/stack_allocator.hpp"

View File

@ -0,0 +1,17 @@
find_package(Threads REQUIRED)
file(GLOB_RECURSE ALL_BENCH_CPP *.cpp)
foreach(ONE_BENCH_CPP ${ALL_BENCH_CPP})
get_filename_component(ONE_BENCH_EXEC ${ONE_BENCH_CPP} NAME_WE)
# Avoid name collision
set(TARGET_NAME Bench_${ONE_BENCH_EXEC})
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})
add_test(${TARGET_NAME} ${ONE_BENCH_EXEC})
endforeach()

View File

@ -0,0 +1,34 @@
#include "benchmark/benchmark_api.h"
#include <set>
#include <vector>
static void BM_VectorInsert(benchmark::State &state)
{
while (state.KeepRunning()) {
std::vector<int> insertion_test;
for (int i = 0, i_end = state.range_x(); i < i_end; i++) {
insertion_test.push_back(i);
}
}
}
// Register the function as a benchmark
BENCHMARK(BM_VectorInsert)->Range(8, 8 << 10);
//~~~~~~~~~~~~~~~~
// Define another benchmark
static void BM_SetInsert(benchmark::State &state)
{
while (state.KeepRunning()) {
std::set<int> insertion_test;
for (int i = 0, i_end = state.range_x(); i < i_end; i++) {
insertion_test.insert(i);
}
}
}
BENCHMARK(BM_SetInsert)->Range(8, 8 << 10);
BENCHMARK_MAIN();

View File

@ -0,0 +1,34 @@
#include "benchmark/benchmark_api.h"
#include <set>
#include <vector>
static void BM_VectorInsert(benchmark::State &state)
{
while (state.KeepRunning()) {
std::vector<int> insertion_test;
for (int i = 0, i_end = state.range_x(); i < i_end; i++) {
insertion_test.push_back(i);
}
}
}
// Register the function as a benchmark
BENCHMARK(BM_VectorInsert)->Range(8, 8 << 10);
//~~~~~~~~~~~~~~~~
// Define another benchmark
static void BM_SetInsert(benchmark::State &state)
{
while (state.KeepRunning()) {
std::set<int> insertion_test;
for (int i = 0, i_end = state.range_x(); i < i_end; i++) {
insertion_test.insert(i);
}
}
}
BENCHMARK(BM_SetInsert)->Range(8, 8 << 10);
BENCHMARK_MAIN();

View File

@ -7,9 +7,10 @@
#include "query/language/cypher/debug/tree_print.hpp"
#include "utils/command_line/arguments.hpp"
#include "utils/terminate_handler.hpp"
#include "utils/variadic/variadic.hpp"
using utils::println;
using std::cout;
using std::endl;
int main(int argc, char *argv[])
{
@ -21,15 +22,14 @@ int main(int argc, char *argv[])
// // query extraction
auto queries = extract_queries(arguments);
for (auto &query : queries)
{
cout << "QUERY: " << query << endl;
println("QUERY: ", query);
auto print_visitor = new PrintVisitor(cout);
cypher::Compiler compiler;
auto tree = compiler.syntax_tree(query);
tree.root->accept(*print_visitor);
cout << endl;
println("");
}
return 0;

View File

@ -4,10 +4,9 @@
#include "query/preprocesor.hpp"
#include "utils/command_line/arguments.hpp"
#include "utils/type_discovery.hpp"
#include "utils/variadic/variadic.hpp"
using std::cout;
using std::cin;
using std::endl;
using utils::println;
int main(int argc, char **argv)
{
@ -22,17 +21,15 @@ int main(int argc, char **argv)
for (auto &query : queries)
{
auto preprocessed = preprocessor.preprocess(query);
cout << "QUERY: " << query << endl;
cout << "STRIPPED QUERY: " << preprocessed.query << endl;
cout << "QUERY HASH: " << preprocessed.hash << endl;
cout << "PROPERTIES:" << endl;
println("QUERY: ", query);
println("STRIPPED QUERY: ", preprocessed.query);
println("QUERY HASH: ", preprocessed.hash);
println("PROPERTIES:");
for (auto property : preprocessed.arguments) {
cout << " " << property << endl;
println(" ", property);
}
cout << "-----------------------------" << endl;
println("-----------------------------");
}
return 0;
}