Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplicated copy of test_perf.hpp #1508

Merged
merged 4 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions production/benchmarks/inc/test_perf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "gaia/direct_access/auto_transaction.hpp"
#include "gaia/logger.hpp"

#include "gaia_internal/common/assert.hpp"
#include "gaia_internal/common/timer.hpp"

namespace gaia
Expand All @@ -27,9 +28,14 @@ static const size_t c_num_iterations = 1;
// This is a hard limit imposed by the db architecture.
static const size_t c_max_insertion_single_txn = (1UL << 16) - 1;

size_t get_duration(std::function<void()> fn)
// Type declaration for the function that contains the benchmarking logic.
using benchmark_fn_t = std::function<void()>;

size_t get_duration(benchmark_fn_t fn)
{
int64_t duration = g_timer_t::get_function_duration(fn);
ASSERT_INVARIANT(duration >= 0, "g_timer_t::get_function_duration() has returned a negative value!");

uint64_t result = duration;
return result;
}
Expand Down Expand Up @@ -106,7 +112,7 @@ class accumulator_t

double_t percentage_difference(size_t expr, size_t plain)
{
return static_cast<double_t>(expr - plain) / static_cast<double_t>(plain) * 100.0;
return ((static_cast<double_t>(expr) - static_cast<double_t>(plain)) / static_cast<double_t>(plain)) * 100.0;
}

void log_performance_difference(
Expand Down Expand Up @@ -136,30 +142,30 @@ void log_performance_difference(
}

void run_performance_test(
std::function<void()> expr_fn,
std::function<void()> clear_db_fn,
benchmark_fn_t expr_fn,
benchmark_fn_t clear_db_fn,
std::string_view message,
bool clear_db_after_each_iteration = true,
size_t num_iterations = c_num_iterations,
size_t num_records = c_num_records)
{
accumulator_t<size_t> expr_accumulator;

for (size_t iteration = 0; iteration < num_iterations; iteration++)
for (size_t iteration = 1; iteration <= num_iterations; ++iteration)
{
gaia_log::app().info("[{}]: {} iteration starting, {} records", message, iteration, num_records);
gaia_log::app().info("[{}]: iteration #{} starting, {} records", message, iteration, num_records);
size_t expr_duration = get_duration(expr_fn);
expr_accumulator.add(expr_duration);

double_t iteration_ms = g_timer_t::ns_to_ms(expr_duration);
gaia_log::app().info("[{}]: {} iteration, completed in {:.2f}ms", message, iteration, iteration_ms);
gaia_log::app().info("[{}]: iteration #{}, completed in {:.2f}ms", message, iteration, iteration_ms);

if (clear_db_after_each_iteration)
{
gaia_log::app().info("[{}]: {} iteration, clearing database", message, iteration);
gaia_log::app().info("[{}]: iteration #{}, clearing database", message, iteration);
size_t clear_database_duration = get_duration(clear_db_fn);
double_t clear_ms = g_timer_t::ns_to_ms(clear_database_duration);
gaia_log::app().info("[{}]: {} iteration, cleared in {:.2f}ms", message, iteration, clear_ms);
gaia_log::app().info("[{}]: iteration #{}, cleared in {:.2f}ms", message, iteration, clear_ms);
}
}

Expand Down
3 changes: 1 addition & 2 deletions production/direct_access/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ set(GAIA_DIRECT_ACCESS_PUBLIC_INCLUDES
message(VERBOSE "GAIA_DIRECT_ACCESS_PUBLIC_INCLUDES=${GAIA_DIRECT_ACCESS_PUBLIC_INCLUDES}")

set(GAIA_DIRECT_ACCESS_PRIVATE_INCLUDES
${GAIA_INC}/internal/common
${GAIA_INC}/internal/db
${GAIA_REPO}/production/benchmarks/inc
${GAIA_REPO}/production/db/inc/core
${GAIA_REPO}/production/db/inc/expressions
${PROJECT_SOURCE_DIR}
Expand Down
1 change: 1 addition & 0 deletions production/direct_access/tests/test_expressions_perf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using namespace gaia::addr_book;
using namespace gaia::addr_book::address_expr;
using namespace gaia::addr_book::employee_expr;
using namespace gaia::benchmark;
using namespace gaia::common;
using namespace gaia::direct_access;
using namespace std;
Expand Down
3 changes: 2 additions & 1 deletion production/direct_access/tests/test_insert_perf_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
#include "gaia_perf_basic.h"
#include "test_perf.hpp"

using namespace gaia::perf_basic;
using namespace gaia::benchmark;
using namespace gaia::common;
using namespace gaia::direct_access;
using namespace gaia::perf_basic;
Copy link
Contributor

@senderista senderista May 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this namespace (and similar) be under gaia::benchmark?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the DAC namespace.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simone-gaia is right. I don't think there is a way to shove in a benchmark name in there. The namespace seems to be derived from the database name.

using namespace std;

class test_insert_perf_basic : public gaia::db::db_catalog_test_base_t
Expand Down
3 changes: 2 additions & 1 deletion production/direct_access/tests/test_insert_perf_idx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
#include "gaia_perf_idx.h"
#include "test_perf.hpp"

using namespace gaia::perf_idx;
using namespace gaia::benchmark;
using namespace gaia::common;
using namespace gaia::direct_access;
using namespace gaia::perf_idx;
using namespace std;

class test_insert_perf_idx : public gaia::db::db_catalog_test_base_t
Expand Down
3 changes: 2 additions & 1 deletion production/direct_access/tests/test_insert_perf_rel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
#include "gaia_perf_rel.h"
#include "test_perf.hpp"

using namespace gaia::perf_rel;
using namespace gaia::benchmark;
using namespace gaia::common;
using namespace gaia::direct_access;
using namespace gaia::perf_rel;
using namespace std;

class test_insert_perf_rel : public gaia::db::db_catalog_test_base_t
Expand Down
229 changes: 0 additions & 229 deletions production/direct_access/tests/test_perf.hpp

This file was deleted.

3 changes: 2 additions & 1 deletion production/direct_access/tests/test_read_perf_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
#include "gaia_perf_basic.h"
#include "test_perf.hpp"

using namespace gaia::perf_basic;
using namespace gaia::benchmark;
using namespace gaia::common;
using namespace gaia::direct_access;
using namespace gaia::perf_basic;
using namespace std;

class test_read_perf_basic : public gaia::db::db_catalog_test_base_t
Expand Down
3 changes: 2 additions & 1 deletion production/direct_access/tests/test_read_perf_rel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
#include "gaia_perf_rel.h"
#include "test_perf.hpp"

using namespace gaia::perf_rel;
using namespace gaia::benchmark;
using namespace gaia::common;
using namespace gaia::direct_access;
using namespace gaia::perf_rel;
using namespace std;

// Creating a relationship lead to 4/5 db operations, which reduces the number
Expand Down
3 changes: 2 additions & 1 deletion production/direct_access/tests/test_update_perf_basic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
#include "gaia_perf_basic.h"
#include "test_perf.hpp"

using namespace gaia::perf_basic;
using namespace gaia::benchmark;
using namespace gaia::common;
using namespace gaia::direct_access;
using namespace gaia::perf_basic;
using namespace std;

class test_update_perf_basic : public gaia::db::db_catalog_test_base_t
Expand Down
2 changes: 1 addition & 1 deletion production/tools/gaia_translate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ if("$CACHE{ENABLE_SDK_TESTS}")

add_gtest(test_rules_perf_basic
"tests/test_rules_perf_basic.cpp;${RULES_TEST_HELPERS};${GAIA_REPO}/production/common/src/debug_logger.cpp"
"${TEST_INCLUDES};${GAIA_REPO}/production/direct_access/tests"
"${TEST_INCLUDES};${GAIA_REPO}/production/benchmarks/inc"
"rt;gaia_system;gaia_db_catalog_test;test_rules_perf_basic_ruleset")

endif()
Loading