Skip to content

Commit

Permalink
Print test durations
Browse files Browse the repository at this point in the history
  • Loading branch information
mls-m5 committed Aug 8, 2024
1 parent 110164a commit 3082e79
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions registertest.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "unittestvars.h"
#include <chrono>
#include <functional>
#include <iomanip>
#include <ios>
Expand Down Expand Up @@ -117,6 +118,7 @@ struct StaticTestSuit {
cout << "=== running test: " << it.name << " ===" << endl;
testResult = 0;

auto start = std::chrono::high_resolution_clock::now();
if (!shouldCatchExceptions) {
it.f();
}
Expand All @@ -141,6 +143,26 @@ struct StaticTestSuit {
testResult = -2;
}
}
auto stop = std::chrono::high_resolution_clock::now();

{
auto duration =
std::chrono::duration_cast<std::chrono::microseconds>(
stop - start);

if (duration.count() > 1000000) {
std::cout << "\n(" << duration.count() / 1000'000.0 << " s)"
<< std::endl;
}
else if (duration.count() > 1000) {
std::cout << "\n(" << duration.count() / 1000.0 << " ms)"
<< std::endl;
}
else {
std::cout << "\n(" << duration.count() << " μs)"
<< std::endl;
}
}
if (testResult == -1) {
cout << " --> not impl" << endl << endl;
it.result = "not implemented";
Expand Down

0 comments on commit 3082e79

Please sign in to comment.