Flow123d  last_with_con_2.0.0-663-gd0e2296
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 
27 using namespace std;
28 
29 
30 #ifdef FLOW123D_HAVE_TIMER_QUERY_PERFORMANCE_COUNTER
31 
32  #include <windows.h>
33 
35  LARGE_INTEGER time;
36  QueryPerformanceCounter (&time);
37  this->ticks = time.QuadPart;
38  }
39 
40 
41  // initialize static frequency when using QueryPerformanceCounter
42  LARGE_INTEGER TimePoint::get_frequency () {
43  LARGE_INTEGER frequency;
44  QueryPerformanceFrequency(&frequency);
45  return frequency;
46  }
47  LARGE_INTEGER TimePoint::frequency = TimePoint::get_frequency ();
48 
49 
50  double TimePoint::operator- (const TimePoint &right) {
51  double difference = this->ticks - right.ticks;
52  return difference / (TimePoint::frequency.QuadPart);
53  }
54 
55 
56 #else
57 
58  #include <chrono>
59 
60 
62  chrono::time_point<chrono::high_resolution_clock> time = chrono::high_resolution_clock::now ();
63  this->ticks = chrono::duration_cast<std::chrono::nanoseconds> (time.time_since_epoch ()).count ();
64  }
65 
66 
67  double TimePoint::operator- (const TimePoint &right) {
68  double difference = this->ticks - right.ticks;
69  return difference / (1 * 1000 * 1000 * 1000);
70  }
71 
72 #endif //FLOW123D_HAVE_TIMER_CHRONO_HIGH_RESOLUTION
73 
long long ticks
Definition: time_point.hh:101
double operator-(const TimePoint &right)
Definition: time_point.cc:67