C Unit Test Framework  0.1
 All Files Functions Enumerations Enumerator Macros Pages
timer.h
1 /*
2  * Copyright 2010 Gerhard Gappmeier <gerhard.gappmeier@ascolab.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Library General Public License as
6  * published by the Free Software Foundation; either version 2 or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this program; if not, write to the
16  * Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 #ifndef __TIMER_H__
20 #define __TIMER_H__
21 
22 #include <stdint.h>
23 #if defined(__linux__) || defined(__QNX__)
24 # include <sys/time.h>
25 #endif /* defined(__linux__) || defined(__QNX__) */
26 #ifdef _WIN32
27 # define WIN32_LEAN_AND_MEAN
28 # include <windows.h>
29 #endif /* _WIN32 */
30 
31 #define TIMER_STATIC_INITIALIZER {{0, 0}, {0, 0}, 0}
32 
33 struct timer {
34 #if defined(__linux__) || defined(__QNX__)
35  struct timeval start;
36  struct timeval end;
37 #endif /* defined(__linux__) || defined(__QNX__) */
38 #ifdef _WIN32
39  LARGE_INTEGER start;
40  LARGE_INTEGER end;
41 #endif /* _WIN32 */
42  uint64_t time;
43 };
44 
45 void timer_init(struct timer *t);
46 void timer_cleanup(struct timer *t);
47 void timer_start(struct timer *t);
48 void timer_stop(struct timer *t);
49 uint64_t timer_compute_time(struct timer *t);
50 uint64_t timer_get_time(struct timer *t);
51 
52 #endif /* __TIMER_H__ */
53