ViennaSHE 1.3.0
Free open-source semiconductor device simulator using spherical harmonics expansions techniques.
timer.hpp
Go to the documentation of this file.
1#ifndef VIENNASHE_UTIL_TIMER_HPP
2#define VIENNASHE_UTIL_TIMER_HPP
3/* ============================================================================
4 Copyright (c) 2011-2022, Institute for Microelectronics,
5 Institute for Analysis and Scientific Computing,
6 TU Wien.
7
8 -----------------
9 ViennaSHE - The Vienna Spherical Harmonics Expansion Boltzmann Solver
10 -----------------
11
12 http://viennashe.sourceforge.net/
13
14 License: MIT (X11), see file LICENSE in the base directory
15=============================================================================== */
16
22#include <iostream>
23
24#ifdef _WIN32
25
26 #include <windows.h>
27 #undef min
28 #undef max
29
30#else
31
32 #include <sys/time.h>
33
34#endif
35
36namespace viennashe
37{
38 namespace util
39 {
40
41#ifdef _WIN32 // WINDOWS
42
43
45 class timer
46 {
47 public:
48
49 timer() { QueryPerformanceFrequency(&freq_); }
50
52 void start()
53 {
54 QueryPerformanceCounter((LARGE_INTEGER*) &start_time_);
55 }
56
58 double get() const
59 {
60 LARGE_INTEGER end_time;
61 QueryPerformanceCounter((LARGE_INTEGER*) &end_time);
62 return (static_cast<double>(end_time.QuadPart) - static_cast<double>(start_time_.QuadPart)) / static_cast<double>(freq_.QuadPart);
63 }
64
65 private:
66 LARGE_INTEGER freq_;
67 LARGE_INTEGER start_time_;
68 };
69
70#else // NOT WINDOWS
71
73 class timer
74 {
75 public:
76
77 timer() : ts_(0) { }
78
80 void start()
81 {
82 struct timeval tval;
83 gettimeofday(&tval, 0);
84 ts_ = tval.tv_sec * 1000000 + tval.tv_usec;
85 }
86
88 double get() const
89 {
90 struct timeval tval;
91 gettimeofday(&tval, 0);
92
93 long end_time = tval.tv_sec * 1000000 + tval.tv_usec;
94
95 return static_cast<double>(end_time - ts_) / 1000000.0;
96 }
97
98 private:
99 long ts_;
100 };
101
102
103#endif
104
105 } // namespace util
106} // namespace viennashe
107
108#endif
A simple timer class.
Definition: timer.hpp:74
void start()
Starts the timer.
Definition: timer.hpp:80
double get() const
Returns the number of seconds elapsed.
Definition: timer.hpp:88
The main ViennaSHE namespace. All functionality resides inside this namespace.
Definition: accessors.hpp:40