Flow123d  DF_patch_fe_data_tables-b828b90
time_point.cc
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file time_point.cc
15  * @brief
16  */
17 
18 //#include <iostream>
19 //#include <stdio.h>
20 //#include <stdlib.h>
21 //#include <string>
22 //#include <time.h>
23 
24 //#include "config.h"
25 #include "time_point.hh"
26 #include <type_traits> // for enable_if<>::type
27 
28 /**
29  * Include either Windows or chrono lib
30  */
31 #ifdef FLOW123D_HAVE_TIMER_QUERY_PERFORMANCE_COUNTER
32 #include <windows.h>
33 #else
34 #include <chrono>
35 #endif //FLOW123D_HAVE_TIMER_CHRONO_HIGH_RESOLUTION
36 
37 using namespace std;
38 
39 
40 #ifdef FLOW123D_HAVE_TIMER_QUERY_PERFORMANCE_COUNTER
41 
42  #include <windows.h>
43 
45  LARGE_INTEGER time;
46  QueryPerformanceCounter (&time);
47  this->ticks = time.QuadPart;
48  }
49 
50 
51  // initialize static frequency when using QueryPerformanceCounter
52  LARGE_INTEGER TimePoint::get_frequency () {
53  LARGE_INTEGER frequency;
54  QueryPerformanceFrequency(&frequency);
55  return frequency;
56  }
57  LARGE_INTEGER TimePoint::frequency = TimePoint::get_frequency ();
58 
59 
60  double TimePoint::operator- (const TimePoint &right) {
61  double difference = this->ticks - right.ticks;
62  return difference / (TimePoint::frequency.QuadPart);
63  }
64 
65 
66 #else
67 
68  #include <chrono>
69 
70 
72  chrono::time_point<chrono::high_resolution_clock> time = chrono::high_resolution_clock::now ();
73  this->ticks = chrono::duration_cast<std::chrono::nanoseconds> (time.time_since_epoch ()).count ();
74  }
75 
76 
77  double TimePoint::operator- (const TimePoint &right) {
78  double difference = this->ticks - right.ticks;
79  return difference / (1 * 1000 * 1000 * 1000);
80  }
81 
82 #endif //FLOW123D_HAVE_TIMER_CHRONO_HIGH_RESOLUTION
83 
double operator-(const TimePoint &right)
Definition: time_point.cc:77