diff options
author | Cedric Nugteren <web@cedricnugteren.nl> | 2017-10-28 14:12:05 +0200 |
---|---|---|
committer | Cedric Nugteren <web@cedricnugteren.nl> | 2017-10-28 14:12:05 +0200 |
commit | bd57dfa435dd6c161b758aef2c68404f837ed689 (patch) | |
tree | 0f7e3a5bf22ea122eda88e63771590699d91b7d8 /src/utilities | |
parent | fa6e5e67f585b77d34c3031c176de9a0f7904aa9 (diff) |
Moved timing function to a separate file
Diffstat (limited to 'src/utilities')
-rw-r--r-- | src/utilities/timing.hpp | 39 |
1 files changed, 39 insertions, 0 deletions
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 <www.cedricnugteren.nl> +// +// This file provides helper functions for time measurement and such. +// +// ================================================================================================= + +#ifndef CLBLAST_TIMING_H_ +#define CLBLAST_TIMING_H_ + +#include <vector> +#include <chrono> + +namespace clblast { +// ================================================================================================= + +template <typename F> +double TimeFunction(const size_t num_runs, F const &function) { + auto timings = std::vector<double>(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<double,std::milli>(elapsed_time).count(); + } + return *std::min_element(timings.begin(), timings.end()); +} + +// ================================================================================================= +} // namespace clblast + +// CLBLAST_TIMING_H_ +#endif |