From bd57dfa435dd6c161b758aef2c68404f837ed689 Mon Sep 17 00:00:00 2001 From: Cedric Nugteren Date: Sat, 28 Oct 2017 14:12:05 +0200 Subject: Moved timing function to a separate file --- CMakeLists.txt | 1 + src/utilities/timing.hpp | 39 +++++++++++++++++++++++++++++++++++++++ test/diagnostics.cpp | 14 +------------- 3 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 src/utilities/timing.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 610e5149..d3b202c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -242,6 +242,7 @@ set(HEADERS # such that they can be discovered by IDEs such as CLion and Visual src/utilities/clblast_exceptions.hpp src/utilities/device_mapping.hpp src/utilities/msvc.hpp + src/utilities/timing.hpp src/utilities/utilities.hpp src/cache.hpp src/cxpp11_common.hpp diff --git a/src/utilities/timing.hpp b/src/utilities/timing.hpp new file mode 100644 index 00000000..3d66de2a --- /dev/null +++ b/src/utilities/timing.hpp @@ -0,0 +1,39 @@ + +// ================================================================================================= +// This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This +// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max- +// width of 100 characters per line. +// +// Author(s): +// Cedric Nugteren +// +// This file provides helper functions for time measurement and such. +// +// ================================================================================================= + +#ifndef CLBLAST_TIMING_H_ +#define CLBLAST_TIMING_H_ + +#include +#include + +namespace clblast { +// ================================================================================================= + +template +double TimeFunction(const size_t num_runs, F const &function) { + auto timings = std::vector(num_runs); + for (auto &timing: timings) { + const auto start_time = std::chrono::steady_clock::now(); + function(); + const auto elapsed_time = std::chrono::steady_clock::now() - start_time; + timing = std::chrono::duration(elapsed_time).count(); + } + return *std::min_element(timings.begin(), timings.end()); +} + +// ================================================================================================= +} // namespace clblast + +// CLBLAST_TIMING_H_ +#endif diff --git a/test/diagnostics.cpp b/test/diagnostics.cpp index af56cd30..b7204fe8 100644 --- a/test/diagnostics.cpp +++ b/test/diagnostics.cpp @@ -15,24 +15,12 @@ #include #include +#include "utilities/timing.hpp" #include "utilities/utilities.hpp" namespace clblast { // ================================================================================================= -template -double TimeFunction(const size_t num_runs, F const &function) { - auto timings = std::vector(num_runs); - for (auto &timing: timings) { - const auto start_time = std::chrono::steady_clock::now(); - function(); - const auto elapsed_time = std::chrono::steady_clock::now() - start_time; - timing = std::chrono::duration(elapsed_time).count(); - } - return *std::min_element(timings.begin(), timings.end()); - -} - void OpenCLDiagnostics(int argc, char *argv[]) { auto arguments = RetrieveCommandLineArguments(argc, argv); -- cgit v1.2.3