ViennaCL - The Vienna Computing Library: examples/benchmarks/benchmark-utils.hpp Source File

ViennaCL - The Vienna Computing Library 1.6.2 Free open-source GPU-accelerated linear algebra and solver library. |

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
benchmark-utils.hpp
Go to the documentation of this file.
1 #ifndef _BENCHMARK_UTILS_HPP_
2 #define _BENCHMARK_UTILS_HPP_
3
4 /* =========================================================================
5 Copyright (c) 2010-2014, Institute for Microelectronics,
6 Institute for Analysis and Scientific Computing,
7 TU Wien.
8 Portions of this software are copyright by UChicago Argonne, LLC.
9
10 -----------------
11 ViennaCL - The Vienna Computing Library
12 -----------------
13
14 Project Head: Karl Rupp rupp@iue.tuwien.ac.at
15
16 (A list of authors and contributors can be found in the PDF manual)
17
18 License: MIT (X11), see file LICENSE in the base directory
19 ============================================================================= */
20
21 #include <iostream>
22
23 inline void printOps(double num_ops, double exec_time)
24 {
25 std::cout << "GFLOPs: " << num_ops / (1000000 * exec_time * 1000) << std::endl;
26 }
27
28
29
30
31 #ifdef _WIN32
32
33 #define WINDOWS_LEAN_AND_MEAN
34 #include <windows.h>
35 #undef min
36 #undef max
37
38 class Timer
39 {
40 public:
41
42 Timer()
43 {
44 QueryPerformanceFrequency(&freq);
45 }
46
47 void start()
48 {
49 QueryPerformanceCounter((LARGE_INTEGER*) &start_time);
50 }
51
52 double get() const
53 {
54 LARGE_INTEGER end_time;
55 QueryPerformanceCounter((LARGE_INTEGER*) &end_time);
56 return (static_cast<double>(end_time.QuadPart) - static_cast<double>(start_time.QuadPart)) / static_cast<double>(freq.QuadPart);
57 }
58
59
60 private:
61 LARGE_INTEGER freq;
62 LARGE_INTEGER start_time;
63 };
64
65 #else
66
67 #include <sys/time.h>
68
69 class Timer
70 {
71 public:
72
73 Timer() : ts(0)
74 {}
75
76 void start()
77 {
78 struct timeval tval;
79 gettimeofday(&tval, NULL);
80 ts = static_cast<double>(tval.tv_sec * 1000000 + tval.tv_usec);
81 }
82
83 double get() const
84 {
85 struct timeval tval;
86 gettimeofday(&tval, NULL);
87 double end_time = static_cast<double>(tval.tv_sec * 1000000 + tval.tv_usec);
88
89 return static_cast<double>(end_time-ts) / 1000000.0;
90 }
91
92 private:
93 double ts;
94 };
95
96
97 #endif
98
99 #endif
Timer::Timer
Timer()
Definition: benchmark-utils.hpp:73
Timer
Definition: benchmark-utils.hpp:69
Timer::start
void start()
Definition: benchmark-utils.hpp:76
printOps
void printOps(double num_ops, double exec_time)
Definition: benchmark-utils.hpp:23