hydrogen 1.2.6
rt_clock.h
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 * Copyright(c) 2008-2025 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
5 *
6 * http://www.hydrogen-music.org
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY, without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see https://www.gnu.org/licenses
20 *
21 */
22
23#ifndef H2_RTCLOCK_H
24#define H2_RTCLOCK_H
25
26#include <core/config.h>
27
28/*
29 RTCLOCK_SETUP
30 RTCLOCK_START
31 ...
32 code to be benchmarked
33 ...
34 RTCLOCK_STOP
35 DEBUGLOG(QString("elapsed time : %1 [ns]").arg(RTCLOCK_NS))
36 DEBUGLOG(QString("elapsed time : %1 [us]").arg(RTCLOCK_US))
37 DEBUGLOG(QString("elapsed time : %1 [ms]").arg(RTCLOCK_MS))
38 */
39
40#if defined(H2CORE_HAVE_DEBUG) and defined(HAVE_RTCLOCK)
41 #include <time.h>
42 //#include <stdint.h>
43 #define RTCLOCK_SETUP struct timespec __t0,__t1; //uint64_t __dt;
44 #define RTCLOCK_START clock_gettime(CLOCK_MONOTONIC, &__t0);
45 #define RTCLOCK_STOP clock_gettime(CLOCK_MONOTONIC, &__t1);
46 #define RTCLOCK_NS (((__t1.tv_sec * 1000000000) + __t1.tv_nsec) - ((__t0.tv_sec * 1000000000) + __t0.tv_nsec))
47 #define RTCLOCK_US (((__t1.tv_sec * 1000000000) + __t1.tv_nsec) - ((__t0.tv_sec * 1000000000) + __t0.tv_nsec))/1000
48 #define RTCLOCK_MS (((__t1.tv_sec * 1000000000) + __t1.tv_nsec) - ((__t0.tv_sec * 1000000000) + __t0.tv_nsec))/1000000
49#else
50 #define RTCLOCK_SETUP
51 #define RTCLOCK_START
52 #define RTCLOCK_STOP
53 #define RTCLOCK_NS -1
54 #define RTCLOCK_US -1
55 #define RTCLOCK_MS -1
56#endif
57
58#endif // H2_RTCLOCK_H