From 3d0170c78d433ac24a32f1be470e28532ef4fe44 Mon Sep 17 00:00:00 2001 From: Morwenn Date: Thu, 13 Jul 2023 16:13:56 +0200 Subject: [PATCH] More running_time use + fixes --- benchmarks/errorbar-plot/bench.cpp | 12 ++++++------ tests/metrics/running_time.cpp | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/benchmarks/errorbar-plot/bench.cpp b/benchmarks/errorbar-plot/bench.cpp index 61015249..763ae9e8 100644 --- a/benchmarks/errorbar-plot/bench.cpp +++ b/benchmarks/errorbar-plot/bench.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2021 Morwenn + * Copyright (c) 2020-2023 Morwenn * SPDX-License-Identifier: MIT */ #include @@ -16,6 +16,7 @@ #include #include #include +#include #include #include "../benchmarking-tools/distributions.h" #include "../benchmarking-tools/filesystem.h" @@ -36,7 +37,7 @@ using sort_f = void (*)(collection_t&); std::pair sorts[] = { { "heap_sort", cppsort::heap_sort }, { "poplar_sort", cppsort::poplar_sort }, - { "smooth_sort", cppsort::smooth_sort } + { "smooth_sort", cppsort::smooth_sort }, }; // Distribution to benchmark against @@ -95,11 +96,10 @@ int main(int argc, char** argv) while (total_end - total_start < max_run_time && times.size() < max_runs_per_size) { collection_t collection; distribution(std::back_inserter(collection), size); - auto start = clock_type::now(); - sort.second(collection); - auto end = clock_type::now(); + auto do_sort = cppsort::metrics::running_time(sort.second); + auto duration = do_sort(collection); assert(std::is_sorted(std::begin(collection), std::end(collection))); - times.push_back(std::chrono::duration(end - start).count()); + times.push_back(duration.value().count()); total_end = clock_type::now(); } diff --git a/tests/metrics/running_time.cpp b/tests/metrics/running_time.cpp index d1b0bbaf..de5369b0 100644 --- a/tests/metrics/running_time.cpp +++ b/tests/metrics/running_time.cpp @@ -34,12 +34,12 @@ TEST_CASE( "basic metrics::running_time tests", "[metrics]" ) { cppsort::metrics::running_time< cppsort::splay_sorter, - std::chrono::milliseconds + std::chrono::microseconds > sorter; auto res = sorter(collection); - CHECK( res >= 0s ); - CHECK( res <= 1s ); + CHECK( res > 0s ); + CHECK( res < 1s ); CHECK( std::is_sorted(collection.begin(), collection.end()) ); }