From 422224bf1cf0d4da29a1e90ce173a73150fe4b2e Mon Sep 17 00:00:00 2001 From: Riyyi Date: Sun, 5 Sep 2021 19:08:28 +0200 Subject: [PATCH] Test: Implement timer --- test/testsuite.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/test/testsuite.cpp b/test/testsuite.cpp index 3b73e43..052839b 100644 --- a/test/testsuite.cpp +++ b/test/testsuite.cpp @@ -1,7 +1,9 @@ #include // size_t +#include // uint32_t #include // fclose, fopen, printf, stdout #include "testsuite.h" +#include "util/timer.h" namespace Test { @@ -22,19 +24,26 @@ void TestSuite::run() size_t caseFailedCount = 0; - for(auto& testCase : m_cases) { - printf("%s\n", testCase.name()); + Util::Timer totalTimer; + + for (auto& testCase : m_cases) { + printf("Start %s\n", testCase.name()); m_currentTestCasePassed = true; + Util::Timer caseTimer; testCase.function()(); + printf(" %s, %luns\n", testCase.name(), caseTimer.elapsedNanoseconds()); if (!m_currentTestCasePassed) { caseFailedCount++; } } - int percentagePassed = (1 - caseFailedCount / (float)m_cases.size()) * 100; + uint32_t percentagePassed = (1 - caseFailedCount / (float)m_cases.size()) * 100; printf("Passed %d%% of tests\n", percentagePassed); + + float elapsed = totalTimer.elapsedNanoseconds() / 1000000.0; + printf("Elapsed: %.3f milliseconds\n", elapsed); } } // namespace Test