From 3082e79c6bdc0971f7567e474b415a6f16fb670d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Lasersk=C3=B6ld?= Date: Thu, 8 Aug 2024 23:29:05 +0200 Subject: [PATCH] Print test durations --- registertest.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/registertest.h b/registertest.h index 1b954ee..4e457d0 100644 --- a/registertest.h +++ b/registertest.h @@ -1,6 +1,7 @@ #pragma once #include "unittestvars.h" +#include #include #include #include @@ -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(); } @@ -141,6 +143,26 @@ struct StaticTestSuit { testResult = -2; } } + auto stop = std::chrono::high_resolution_clock::now(); + + { + auto duration = + std::chrono::duration_cast( + 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";