performance_tests: add a --verbose flag, and default to terse

This commit is contained in:
moneromooo-monero 2018-01-14 23:02:34 +00:00
parent 939bc22332
commit 0793184bd0
No known key found for this signature in database
GPG key ID: 686F07454D6CEFC3
2 changed files with 116 additions and 102 deletions

View file

@ -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) ">")