diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-01-14 23:02:34 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2018-09-11 13:37:26 +0000 |
commit | 0793184bd008b51cc6865738a86bcd10792d42e0 (patch) | |
tree | 36526dc62fa6117f3cabf7fd644ac24c947b42e0 /tests/performance_tests/performance_tests.h | |
parent | add Straus multiexp (diff) | |
download | monero-0793184bd008b51cc6865738a86bcd10792d42e0.tar.xz |
performance_tests: add a --verbose flag, and default to terse
Diffstat (limited to 'tests/performance_tests/performance_tests.h')
-rw-r--r-- | tests/performance_tests/performance_tests.h | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/tests/performance_tests/performance_tests.h b/tests/performance_tests/performance_tests.h index 29d296571..6f613e0a5 100644 --- a/tests/performance_tests/performance_tests.h +++ b/tests/performance_tests/performance_tests.h @@ -67,8 +67,9 @@ template <typename T> class test_runner { public: - test_runner() + test_runner(bool verbose = true) : m_elapsed(0) + , m_verbose(verbose) { } @@ -81,7 +82,8 @@ public: performance_timer timer; timer.start(); warm_up(); - std::cout << "Warm up: " << timer.elapsed_ms() << " ms" << std::endl; + if (m_verbose) + std::cout << "Warm up: " << timer.elapsed_ms() << " ms" << std::endl; timer.start(); for (size_t i = 0; i < T::loop_count; ++i) @@ -120,21 +122,29 @@ private: private: volatile uint64_t m_warm_up; ///<! This field is intended for preclude compiler optimizations int m_elapsed; + bool m_verbose; }; template <typename T> -void run_test(const std::string &filter, const char* test_name) +void run_test(const std::string &filter, bool verbose, const char* test_name) { boost::smatch match; if (!filter.empty() && !boost::regex_match(std::string(test_name), match, boost::regex(filter))) return; - test_runner<T> runner; + test_runner<T> runner(verbose); if (runner.run()) { - std::cout << test_name << " - OK:\n"; - std::cout << " loop count: " << T::loop_count << '\n'; - std::cout << " elapsed: " << runner.elapsed_time() << " ms\n"; + if (verbose) + { + std::cout << test_name << " - OK:\n"; + std::cout << " loop count: " << T::loop_count << '\n'; + std::cout << " elapsed: " << runner.elapsed_time() << " ms\n"; + } + else + { + std::cout << test_name << " (" << T::loop_count << " calls) - OK:"; + } const char *unit = "ms"; int time_per_call = runner.time_per_call(); if (time_per_call < 30000) { @@ -145,7 +155,7 @@ void run_test(const std::string &filter, const char* test_name) unit = "µs"; #endif } - std::cout << " time per call: " << time_per_call << " " << unit << "/call\n" << std::endl; + std::cout << (verbose ? " time per call: " : " ") << time_per_call << " " << unit << "/call" << (verbose ? "\n" : "") << std::endl; } else { @@ -154,7 +164,8 @@ void run_test(const std::string &filter, const char* test_name) } #define QUOTEME(x) #x -#define TEST_PERFORMANCE0(filter, test_class) run_test< test_class >(filter, QUOTEME(test_class)) -#define TEST_PERFORMANCE1(filter, test_class, a0) run_test< test_class<a0> >(filter, QUOTEME(test_class<a0>)) -#define TEST_PERFORMANCE2(filter, test_class, a0, a1) run_test< test_class<a0, a1> >(filter, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ">") -#define TEST_PERFORMANCE3(filter, test_class, a0, a1, a2) run_test< test_class<a0, a1, a2> >(filter, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ", " QUOTEME(a2) ">") +#define TEST_PERFORMANCE0(filter, verbose, test_class) run_test< test_class >(filter, verbose, QUOTEME(test_class)) +#define TEST_PERFORMANCE1(filter, verbose, test_class, a0) run_test< test_class<a0> >(filter, verbose, QUOTEME(test_class<a0>)) +#define TEST_PERFORMANCE2(filter, verbose, test_class, a0, a1) run_test< test_class<a0, a1> >(filter, verbose, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ">") +#define TEST_PERFORMANCE3(filter, verbose, test_class, a0, a1, a2) run_test< test_class<a0, a1, a2> >(filter, verbose, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ", " QUOTEME(a2) ">") +#define TEST_PERFORMANCE4(filter, verbose, test_class, a0, a1, a2, a3) run_test< test_class<a0, a1, a2, a3> >(filter, verbose, QUOTEME(test_class) "<" QUOTEME(a0) ", " QUOTEME(a1) ", " QUOTEME(a2) ", " QUOTEME(a3) ">") |