Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit f95adc5ca8362f0df5be19548e1b674f5207a922
Merge: 5f000ca f4959fb
Author: Markus Dreseler <[email protected]>
Date:   Wed Feb 22 18:12:05 2017 +0100

    Merge branch 'develop' into google_benchmark

commit 5f000ca532b8265c8985539c6095ac2b75418269
Merge: fec4361 14303fb
Author: Markus Dreseler <[email protected]>
Date:   Wed Feb 22 18:11:35 2017 +0100

    Merge branch 'google_benchmark' of gitlab.hpi.de:OpossumDB/OpossumDB into google_benchmark

commit 14303fb48cd55ff5d5d722aca58c523b51c602b3
Author: Nils Thamm <[email protected]>
Date:   Tue Feb 21 19:09:51 2017 +0100

    Refactoring

commit a70aebc459f72ae84605cdc7326160bec652f8d2
Author: Nils Thamm <[email protected]>
Date:   Wed Feb 15 18:11:40 2017 +0100

    Added Warm up run and clearing cache

commit d59b657cb1a9e5aced7349472a02585fe8ad67c4
Author: Nils Thamm <[email protected]>
Date:   Wed Feb 15 17:15:18 2017 +0100

    Refactored registration of benchmarks

commit a5c42a75c17644d95bc7d4272db6d0ac80d2479f
Merge: 3b6d957 fab3d9c
Author: Nils Thamm <[email protected]>
Date:   Fri Feb 10 15:40:15 2017 +0100

    Merge remote-tracking branch 'origin/develop' into google_benchmark

commit 3b6d95761ca47230bdc00177bd8ff4472a50795b
Author: Nils Thamm <[email protected]>
Date:   Fri Feb 10 15:33:20 2017 +0100

    Formating

commit 4eefa29875ff9fb4300b2312a2adb3469beec58e
Author: Nils Thamm <[email protected]>
Date:   Fri Feb 10 14:22:49 2017 +0100

    Removed Args calls

commit 39c1ba042a86943bc8598e78f5723b6a1ac50874
Author: Nils Thamm <[email protected]>
Date:   Wed Feb 8 16:35:12 2017 +0100

    Revert "Test commit"

    This reverts commit 3acaef6487c4e7700faeeac74147155b45133421.

commit 3acaef6487c4e7700faeeac74147155b45133421
Author: Nils Thamm <[email protected]>
Date:   Wed Feb 8 16:01:12 2017 +0100

    Test commit

commit e01db8c46b273e49ccde87326693470222003aea
Author: Nils Thamm <[email protected]>
Date:   Wed Feb 8 15:37:58 2017 +0100

    Changed benchmark output format

commit a971a7cfd002b9718aa1460654daa9d2c318fa31
Author: Nils Thamm <[email protected]>
Date:   Sat Jan 28 10:51:00 2017 +0100

    Adding TableGenerator class

commit 736257b1848d40ff6f7d4623d101b53bd9fb7c3e
Author: Nils Thamm <[email protected]>
Date:   Sat Jan 28 10:18:44 2017 +0100

    Adding Documentation for Args call in benchmarks

commit fec4361bc797279b1cc41658241984f10560b5f8
Author: Markus Dreseler <[email protected]>
Date:   Fri Jan 27 16:33:55 2017 +0100

    Fixed dummy.cpp

commit ba3f9e2df9c254b605a26ffa6f84af6f4ca4ac97
Author: Nils Thamm <[email protected]>
Date:   Fri Jan 27 11:49:36 2017 +0100

    Removing file that should have already been deleted

commit 1c8bc7a7b1dd13cdde42895367a461c08ea8ec32
Author: Nils Thamm <[email protected]>
Date:   Fri Jan 27 11:37:02 2017 +0100

    Trying to fix mac os linker warnings

commit 0c6b60c3a41c714b32017a3c9d5a8a9dc285875d
Author: Nils Thamm <[email protected]>
Date:   Fri Jan 27 11:29:08 2017 +0100

    mend

commit f149ec0ccf8f0753ccc8d8f67beb0c195a1099ce
Author: Nils Thamm <[email protected]>
Date:   Fri Jan 27 11:18:31 2017 +0100

    Moved load_table

commit 06da02eb0e97fde2f6d8527eb2d20e33d8e23a7d
Merge: 23248d7 5ae37c9
Author: Nils Thamm <[email protected]>
Date:   Fri Jan 27 11:16:20 2017 +0100

    Merge remote-tracking branch 'origin/develop' into google_benchmark

commit 23248d738888a7ac7489e74f1c3339d2592fd46f
Author: Nils Thamm <[email protected]>
Date:   Sat Jan 21 14:37:35 2017 +0100

    Added example benchmark for some operators

commit 2161b44840d5c0f9feaed2325ac0a3d4cb5bbe48
Author: Nils Thamm <[email protected]>
Date:   Sat Jan 21 13:49:49 2017 +0100

    Adding a commented template

commit d884f9a6bfd67dca883322625bed4040fb1da646
Author: Nils Thamm <[email protected]>
Date:   Sat Jan 21 13:24:02 2017 +0100

    (Hopefully) Suppress linker warning on macOS for benchmark build

commit 363f63c3ee07d325b6c59c046d53b96e3a6f80de
Author: Nils Thamm <[email protected]>
Date:   Sat Jan 21 13:05:32 2017 +0100

    Added generate table from scheduling PR

commit b99e1fb337d18f53c65770f4a5cfe2a8685de6f0
Merge: 68d87d9 9c5795b
Author: Nils Thamm <[email protected]>
Date:   Fri Jan 20 16:03:59 2017 +0100

    Merge branch 'master' into google_benchmark

commit 68d87d9da3d804730da71ac2ceeb73331a5b2648
Author: Nils Thamm <[email protected]>
Date:   Fri Jan 20 16:03:33 2017 +0100

    Building benchmark library wit -O3 flag (CMAKE_CXX_FLAGS_RELEASE)

commit 3cb78bd2e54212ec97523183fed59ef354dc7093
Author: Nils Thamm <[email protected]>
Date:   Fri Jan 20 15:52:20 2017 +0100

    First Benchmark fixture

commit cc79157a1964d9522caf8714ac93b64840ff99e9
Author: Nils Thamm <[email protected]>
Date:   Fri Jan 20 15:38:39 2017 +0100

    Building library as not debug

commit 59f7568b701070f466c641f39b5a0e2e6c79a169
Author: Nils Thamm <[email protected]>
Date:   Thu Jan 12 17:09:39 2017 +0100

    Adding csv output for make benchmark

commit 6e73ceef2434468b193c76191bae753d19f33722
Author: Nils Thamm <[email protected]>
Date:   Wed Jan 11 16:01:42 2017 +0100

    Fixing compiler error on MacOS

commit 3e6a009ba9d3a78d8e885bdfa9beac47c9a73f43
Author: Nils Thamm <[email protected]>
Date:   Wed Jan 11 14:53:43 2017 +0100

    First try with google benchmark
  • Loading branch information
mrks committed Feb 22, 2017
1 parent f4959fb commit 9fb3bb9
Show file tree
Hide file tree
Showing 16 changed files with 336 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ build/*
*.make
Makefile*
coverage
*.sublime-*
benchmark.json
*.sublime-*
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "third_party/googletest"]
path = third_party/googletest
url = https://github.com/google/googletest.git
[submodule "third_party/benchmark"]
path = third_party/benchmark
url = https://github.com/google/benchmark.git
22 changes: 20 additions & 2 deletions premake4.lua
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,30 @@ solution "opossum"
configuration "Debug"
defines { "IS_DEBUG=1" }
flags { "Symbols" }
prebuildcommands { "find src -iname \"*.cpp\" -o -iname \"*.hpp\" | xargs -I{} sh -c \"clang-format -i -style=file '{}'\"" }
-- TODO Shouldn't this be part of the pre-commit hook? "make" should never touch the code

configuration "Release"
defines { "IS_DEBUG=0" }
flags { "OptimizeSpeed" }
buildoptions { "-march=native" }

configuration "Debug or Release"
prebuildcommands { "find src -iname \"*.cpp\" -o -iname \"*.hpp\" | xargs -I{} sh -c \"clang-format -i -style=file '{}'\"" }
-- TODO Shouldn't this be part of the pre-commit hook? "make" should never touch the code

project "googletest"
kind "StaticLib"
files { "third_party/googletest/googletest/src/gtest-all.cc" }
includedirs { "third_party/googletest/googletest", "third_party/googletest/googletest/include" }

project "googlebenchmark"
kind "StaticLib"
buildoptions {"-O3"}
files { "third_party/benchmark/src/**.cc", "third_party/benchmark_fix/dummy.cc" }
includedirs { "third_party/benchmark/src", "third_party/benchmark/include" }

configuration "Debug or Release"
defines {"NDEBUG", "HAVE_STD_REGEX"}

project "opossum"
kind "StaticLib"
files { "src/lib/**.hpp", "src/lib/**.cpp", "src/bin/server.cpp" }
Expand Down Expand Up @@ -152,6 +162,14 @@ project "asan"
linkoptions { "-fsanitize=address" }
postbuildcommands { "./build/asan" }

project "benchmark"
kind "ConsoleApp"

links { "opossum", "googlebenchmark" }
files { "src/benchmark/**.hpp", "src/benchmark/**.cpp" }
includedirs { "third_party/benchmark/include" }
--postbuildcommands { "./build/benchmark --benchmark_format=json > benchmark.json" }

project "coverage"
kind "ConsoleApp"

Expand Down
55 changes: 55 additions & 0 deletions src/benchmark/base_fixture.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "benchmark/benchmark.h"

#include "../lib/operators/get_table.hpp"
#include "../lib/storage/storage_manager.hpp"
#include "../lib/storage/table.hpp"
#include "../lib/types.hpp"
#include "table_generator.hpp"

namespace opossum {

// Defining the base fixture class
class BenchmarkFixture : public benchmark::Fixture {
public:
BenchmarkFixture() {
// Generating a test table with generate_table function from table_generator.cpp

auto table_generator = std::make_shared<TableGenerator>();

auto table = table_generator->get_table();

opossum::StorageManager::get().add_table("benchmark_table_one", std::move(table));

auto table_generator2 = std::make_shared<TableGenerator>();

auto table2 = table_generator2->get_table();

opossum::StorageManager::get().add_table("benchmark_table_two", std::move(table2));

_gt_a = std::make_shared<GetTable>("benchmark_table_one");
_gt_b = std::make_shared<GetTable>("benchmark_table_two");
_gt_a->execute();
_gt_b->execute();
}

virtual void TearDown(const ::benchmark::State&) { opossum::StorageManager::get().reset(); }

protected:
std::shared_ptr<GetTable> _gt_a;
std::shared_ptr<GetTable> _gt_b;

void clear_cache() {
std::vector<int> clear = std::vector<int>();
clear.resize(500 * 1000 * 1000, 42);
for (uint i = 0; i < clear.size(); i++) {
clear[i] += 1;
}
clear.resize(0);
}
};
} // namespace opossum
2 changes: 2 additions & 0 deletions src/benchmark/benchmark_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include <benchmark/benchmark.h>
BENCHMARK_MAIN();
35 changes: 35 additions & 0 deletions src/benchmark/benchmark_template.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <iostream>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "benchmark/benchmark.h"

#include "../lib/operators/difference.hpp"
#include "../lib/operators/get_table.hpp"
#include "../lib/operators/projection.hpp"
#include "../lib/storage/storage_manager.hpp"
#include "../lib/storage/table.hpp"
#include "../lib/types.hpp"
#include "base_fixture.cpp"
#include "table_generator.hpp"

namespace opossum {
/*
BENCHMARK_F(BenchmarkFixture, BM_Template)(benchmark::State& state) {
// Google benchmark automaticly determines a number of executions. The code that should be measured multiple times
// goes in the while loop. Executions before the loop won't be measured.
clear_cache();
auto warm_up = std::make_shared<Difference>(_gt_a, _gt_b);
warm_up->execute();
while (state.KeepRunning()) {
state.PauseTiming();
// If you have something to be configured wich shouldn't be measured, you can pause the measures.
state.ResumeTiming();
auto difference = std::make_shared<opossum::Difference>(_gt_a, _gt_b);
difference->execute();
}
}
*/
} // namespace opossum
27 changes: 27 additions & 0 deletions src/benchmark/operators/difference_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <memory>
#include <string>
#include <utility>

#include "benchmark/benchmark.h"

#include "../../lib/operators/difference.hpp"
#include "../../lib/operators/get_table.hpp"
#include "../../lib/storage/storage_manager.hpp"
#include "../../lib/storage/table.hpp"
#include "../../lib/types.hpp"
#include "../base_fixture.cpp"
#include "../table_generator.hpp"

namespace opossum {

BENCHMARK_F(BenchmarkFixture, BM_Difference)(benchmark::State& state) {
clear_cache();
auto warm_up = std::make_shared<Difference>(_gt_a, _gt_b);
warm_up->execute();
while (state.KeepRunning()) {
auto difference = std::make_shared<Difference>(_gt_a, _gt_b);
difference->execute();
}
}

} // namespace opossum
27 changes: 27 additions & 0 deletions src/benchmark/operators/product_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <memory>
#include <string>
#include <utility>

#include "benchmark/benchmark.h"

#include "../../lib/operators/get_table.hpp"
#include "../../lib/operators/product.hpp"
#include "../../lib/storage/storage_manager.hpp"
#include "../../lib/storage/table.hpp"
#include "../../lib/types.hpp"
#include "../base_fixture.cpp"
#include "../table_generator.hpp"

namespace opossum {

BENCHMARK_F(BenchmarkFixture, BM_Product)(benchmark::State& state) {
clear_cache();
auto warm_up = std::make_shared<Product>(_gt_a, _gt_b);
warm_up->execute();
while (state.KeepRunning()) {
auto product = std::make_shared<Product>(_gt_a, _gt_b);
product->execute();
}
}

} // namespace opossum
27 changes: 27 additions & 0 deletions src/benchmark/operators/sort_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <memory>
#include <string>
#include <utility>

#include "benchmark/benchmark.h"

#include "../../lib/operators/get_table.hpp"
#include "../../lib/operators/sort.hpp"
#include "../../lib/storage/storage_manager.hpp"
#include "../../lib/storage/table.hpp"
#include "../../lib/types.hpp"
#include "../base_fixture.cpp"
#include "../table_generator.hpp"

namespace opossum {

BENCHMARK_F(BenchmarkFixture, BM_Sort)(benchmark::State& state) {
clear_cache();
auto warm_up = std::make_shared<Sort>(_gt_a, "a");
warm_up->execute();
while (state.KeepRunning()) {
auto sort = std::make_shared<Sort>(_gt_a, "a");
sort->execute();
}
}

} // namespace opossum
27 changes: 27 additions & 0 deletions src/benchmark/operators/table_scan_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <memory>
#include <string>
#include <utility>

#include "benchmark/benchmark.h"

#include "../../lib/operators/get_table.hpp"
#include "../../lib/operators/table_scan.hpp"
#include "../../lib/storage/storage_manager.hpp"
#include "../../lib/storage/table.hpp"
#include "../../lib/types.hpp"
#include "../base_fixture.cpp"
#include "../table_generator.hpp"

namespace opossum {

BENCHMARK_F(BenchmarkFixture, BM_TableScan)(benchmark::State& state) {
clear_cache();
auto warm_up = std::make_shared<TableScan>(_gt_a, "a", ">=", 7);
warm_up->execute();
while (state.KeepRunning()) {
auto table_scan = std::make_shared<TableScan>(_gt_a, "a", ">=", 7);
table_scan->execute();
}
}

} // namespace opossum
27 changes: 27 additions & 0 deletions src/benchmark/operators/union_all_benchmark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <memory>
#include <string>
#include <utility>

#include "benchmark/benchmark.h"

#include "../../lib/operators/get_table.hpp"
#include "../../lib/operators/union_all.hpp"
#include "../../lib/storage/storage_manager.hpp"
#include "../../lib/storage/table.hpp"
#include "../../lib/types.hpp"
#include "../base_fixture.cpp"
#include "../table_generator.hpp"

namespace opossum {

BENCHMARK_F(BenchmarkFixture, BM_UnionAll)(benchmark::State& state) {
clear_cache();
auto warm_up = std::make_shared<UnionAll>(_gt_a, _gt_b);
warm_up->execute();
while (state.KeepRunning()) {
auto union_all = std::make_shared<UnionAll>(_gt_a, _gt_b);
union_all->execute();
}
}

} // namespace opossum
60 changes: 60 additions & 0 deletions src/benchmark/table_generator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "table_generator.hpp"
#include <assert.h>
#include <fstream>
#include <memory>
#include <random>
#include <string>
#include <utility>
#include <vector>
#include "types.hpp"

namespace opossum {

std::shared_ptr<Table> TableGenerator::get_table() {
std::shared_ptr<Table> table = std::make_shared<Table>(_chunk_size);
std::vector<std::vector<int>> value_vectors;
auto vector_size = _chunk_size > 0 ? _chunk_size : _num_rows;
/*
* Generate table layout with column names from 'a' to 'z'.
* Create a vector for each column.
*/
for (size_t i = 0; i < _num_columns; i++) {
auto column_name = std::string(1, static_cast<char>(static_cast<int>('a') + i));
table->add_column(column_name, "int", false);
value_vectors.emplace_back(std::vector<int>(vector_size));
}
auto chunk = Chunk();
std::default_random_engine engine;
std::uniform_int_distribution<int> dist(0, _max_different_value);
for (size_t i = 0; i < _num_rows; i++) {
/*
* Add vectors to chunk when full, and add chunk to table.
* Reset vectors and chunk.
*/
if (i % vector_size == 0 && i > 0) {
for (size_t j = 0; j < _num_columns; j++) {
chunk.add_column(std::make_shared<ValueColumn<int>>(std::move(value_vectors[j])));
value_vectors[j] = std::vector<int>(vector_size);
}
table->add_chunk(std::move(chunk));
chunk = Chunk();
}
/*
* Set random value for every column.
*/
for (size_t j = 0; j < _num_columns; j++) {
value_vectors[j][i % vector_size] = dist(engine);
}
}
/*
* Add remaining values to table, if any.
*/
if (value_vectors[0].size() > 0) {
for (size_t j = 0; j < _num_columns; j++) {
chunk.add_column(std::make_shared<ValueColumn<int>>(std::move(value_vectors[j])));
}
table->add_chunk(std::move(chunk));
}
return table;
}
} // namespace opossum
16 changes: 16 additions & 0 deletions src/benchmark/table_generator.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once
#include <memory>
#include <string>
#include "storage/table.hpp"
namespace opossum {
class TableGenerator {
public:
std::shared_ptr<Table> get_table();

protected:
const size_t _num_columns = 10;
const size_t _num_rows = 5 * 1000;
const size_t _chunk_size = 100;
const int _max_different_value = 1000;
};
} // namespace opossum
5 changes: 5 additions & 0 deletions src/lib/storage/value_column.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class ValueColumn : public BaseColumn {
public:
ValueColumn() = default;

/**
* This constructor shall only be used for testing purposes.
*/
explicit ValueColumn(std::vector<T>&& values) : _values(std::move(values)) {}

// return the value at a certain position. If you want to write efficient operators, back off!
const AllTypeVariant operator[](const size_t i) const override { return _values.at(i); }

Expand Down
1 change: 1 addition & 0 deletions third_party/benchmark
Submodule benchmark added at 4bf28e
2 changes: 2 additions & 0 deletions third_party/benchmark_fix/dummy.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This is a dummy file that avoids the "file has no symbols" warning on some systems (e.g. Clang on OSX)
int gl_dummy_symbol;

0 comments on commit 9fb3bb9

Please sign in to comment.