skiplist benchmark

This commit is contained in:
Marko Budiselic 2016-10-04 15:09:21 +02:00
parent 34c8adbcb9
commit f5cf9c72d2
7 changed files with 108 additions and 27 deletions

View File

@ -376,6 +376,8 @@ option(TOOLS "Build tool executables" ON)
message(STATUS "TOOLS binaries: ${TOOLS}")
option(TESTS "Build test binaries" ON)
message(STATUS "TESTS binaries: ${TESTS}")
option(BENCHMARK "Build benchmark binaries" ON)
message(STATUS "BENCHMARK binaries: ${BENCHMARK}")
# -- binaries -----------------------------------------------------------------
# -- barrier - this is the way how the engine is isolated so it can be shipped
# wherever, the code is completely hidden behind the barrier, during the
@ -511,6 +513,10 @@ if (POC)
add_subdirectory(poc)
endif()
# benchmark binaries
if (BENCHMARK)
add_subdirectory(benchmark)
endif()
# memgraph build name
execute_process(

8
benchmark/CMakeLists.txt Normal file
View File

@ -0,0 +1,8 @@
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})

29
benchmark/skiplist.cpp Normal file
View File

@ -0,0 +1,29 @@
#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

@ -4,5 +4,5 @@ barrier_template_cpu_cpp_path: "./template/barrier_template_code_cpu.cpp"
template_cpu_hpp_path: "./template/template_code_cpu.hpp"
snapshots_path: "snapshots"
cleaning_cycle_sec: "300"
snapshot_cycle_sec: "3600"
snapshot_cycle_sec: "60"
max_retained_snapshots: "3"

View File

@ -22,3 +22,47 @@ auto timer(F func, Args &&... args)
func(std::forward<Args>(args)...);
return to_duration<DurationUnit>(time_now() - start_time);
}
// idea from Optimized C++ Kurt Guntheroth 2016
// TODO: make more modular and easier to use
class Stopwatch
{
public:
Stopwatch() : start(std::chrono::system_clock::time_point::min()) {}
void Clear()
{
start = std::chrono::system_clock::time_point::min();
}
bool IsStarted() const
{
return (start != std::chrono::system_clock::time_point::min());
}
void Start()
{
start = std::chrono::system_clock::now();
}
unsigned long GetMs()
{
if (IsStarted())
{
std::chrono::system_clock::duration diff;
diff = std::chrono::system_clock::now() - start;
return (unsigned) (std::chrono::duration_cast<ms>(diff).count());
}
return 0;
}
~Stopwatch()
{
std::cout << "Time: " << GetMs() << "ms" << std::endl;
}
private:
std::chrono::system_clock::time_point start;
};

View File

@ -11,11 +11,11 @@ target_link_libraries(poc_astar Threads::Threads)
target_link_libraries(poc_astar ${fmt_static_lib})
target_link_libraries(poc_astar ${yaml_static_lib})
add_executable(profile profile.cpp)
target_link_libraries(profile memgraph)
target_link_libraries(profile Threads::Threads)
target_link_libraries(profile ${fmt_static_lib})
target_link_libraries(profile ${yaml_static_lib})
add_executable(powerlinx_profile profile.cpp)
target_link_libraries(powerlinx_profile memgraph)
target_link_libraries(powerlinx_profile Threads::Threads)
target_link_libraries(powerlinx_profile ${fmt_static_lib})
target_link_libraries(powerlinx_profile ${yaml_static_lib})
add_executable(csv_import csv_import.cpp)
target_link_libraries(csv_import memgraph)

View File

@ -1,46 +1,46 @@
#include "profile.hpp"
#include "barrier/barrier.cpp"
#include "database/db.hpp"
#include "database/db_accessor.hpp"
#include <chrono>
#include <ctime>
#include <strings.h>
#include <unistd.h>
#include <unordered_map>
#include "barrier/barrier.cpp"
#include "database/db.hpp"
#include "database/db_accessor.hpp"
#include "communication/bolt/v1/serialization/bolt_serializer.hpp"
#include "import/csv_import.hpp"
#include "logging/default.hpp"
#include "logging/streams/stdout.hpp"
#include "utils/command_line/arguments.hpp"
#include "profile.hpp"
using namespace std;
// (company, {type_name, score})
using company_profile_type =
pair<barrier::VertexAccessor, unordered_map<string, double>>;
// Accepts flags for csv import.
// Accepted flags for CSV import.
// -db name # will create database with that name.
// -s true # will create snapshot of the database after import.
// -s true # will create snapshot of the database after import.
int main(int argc, char **argv)
{
// initialize logger
logging::init_async();
logging::log->pipe(std::make_unique<Stdout>());
// read program arguments
auto para = all_arguments(argc, argv);
Db db(get_argument(para, "-db", "powerlinks_profile"));
// import database
import_csv_from_arguments(db, para);
{
DbAccessor t(db);
vector<company_profile_type> company_profiles;
// QUERY BENCHMARK
// query benchmark
auto begin = clock();
int n = for_all_companys(barrier::trans(t), company_profiles);
clock_t end = clock();
@ -51,6 +51,7 @@ int main(int argc, char **argv)
return 0;
}
// performance statistics
cout << endl
<< "Query duration: " << (elapsed_s / n) * 1000 * 1000 << " [us]"
<< endl;
@ -67,8 +68,8 @@ int main(int argc, char **argv)
int company_id = std::stoi(get_argument(para, "-company_id", "230216"));
for (auto &company_profile : company_profiles) {
auto prop_vertex_id = t.vertex_property_key<Int64>("company_id");
auto db_company_id = *barrier::trans(company_profile.first)
.at(prop_vertex_id).get();
auto db_company_id =
*barrier::trans(company_profile.first).at(prop_vertex_id).get();
if (db_company_id == company_id) {
cout << endl << "CompanyID: " << company_id << endl;
for (auto e : company_profile.second) {
@ -77,20 +78,13 @@ int main(int argc, char **argv)
}
}
// double sum = 0;
// for (auto r : coll) {
// for (auto e : r.second) {
// sum += e.second;
// }
// }
// cout << endl << endl << "Compiler sum " << sum << endl;
t.commit();
}
if (get_argument(para, "-s", "false") == "true") {
db.snap_engine.make_snapshot();
}
// usleep(1000 * 1000 * 60);
return 0;