summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric Nugteren <web@cedricnugteren.nl>2017-10-28 14:12:05 +0200
committerCedric Nugteren <web@cedricnugteren.nl>2017-10-28 14:12:05 +0200
commitbd57dfa435dd6c161b758aef2c68404f837ed689 (patch)
tree0f7e3a5bf22ea122eda88e63771590699d91b7d8
parentfa6e5e67f585b77d34c3031c176de9a0f7904aa9 (diff)
Moved timing function to a separate file
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/utilities/timing.hpp39
-rw-r--r--test/diagnostics.cpp14
3 files changed, 41 insertions, 13 deletions
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 <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
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 <chrono>
#include <algorithm>
+#include "utilities/timing.hpp"
#include "utilities/utilities.hpp"
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());
-
-}
-
void OpenCLDiagnostics(int argc, char *argv[]) {
auto arguments = RetrieveCommandLineArguments(argc, argv);