-
Notifications
You must be signed in to change notification settings - Fork 6
/
timemeasurement.h
57 lines (48 loc) · 1.75 KB
/
timemeasurement.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright (c) 2012 Vadym Kliuchnikov sqct(dot)software(at)gmail(dot)com
//
// This file is part of SQCT.
//
// SQCT is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// SQCT is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with SQCT. If not, see <http://www.gnu.org/licenses/>.
//
#ifndef TIMEMEASUREMENT_H
#define TIMEMEASUREMENT_H
#include <time.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
typedef boost::multiprecision::int512_t i512;
typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<200> > f200;
typedef timespec timepoint;
static i512 time_diff_i( const timepoint& t1, const timepoint& t2)
{
i512 nano_inv = 1000000000;
i512 T1 = i512(t1.tv_sec) * nano_inv + i512(t1.tv_nsec);
i512 T2 = i512(t2.tv_sec) * nano_inv + i512(t2.tv_nsec);
return T2 - T1;
}
static double time_diff_d( const timepoint& t1, const timepoint& t2)
{
i512 dt = time_diff_i(t1,t2);
i512 k = 1000000; //get miliseconds
f200 r = f200(dt) / f200(k);
return r.convert_to<double>();
}
static void get_timepoint( timepoint& t )
{
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t);
}
static void get_timepoint_real( timepoint& t )
{
clock_gettime(CLOCK_REALTIME, &t);
}
#endif // TIMEMEASUREMENT_H