GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
rtimer.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * MODULE: iostream
4  *
5 
6  * COPYRIGHT (C) 2007 Laura Toma
7  *
8  *
9 
10  * Iostream is a library that implements streams, external memory
11  * sorting on streams, and an external memory priority queue on
12  * streams. These are the fundamental components used in external
13  * memory algorithms.
14 
15  * Credits: The library was developed by Laura Toma. The kernel of
16  * class STREAM is based on the similar class existent in the GPL TPIE
17  * project developed at Duke University. The sorting and priority
18  * queue have been developed by Laura Toma based on communications
19  * with Rajiv Wickremesinghe. The library was developed as part of
20  * porting Terraflow to GRASS in 2001. PEARL upgrades in 2003 by
21  * Rajiv Wickremesinghe as part of the Terracost project.
22 
23  *
24  * This program is free software; you can redistribute it and/or modify
25  * it under the terms of the GNU General Public License as published by
26  * the Free Software Foundation; either version 2 of the License, or
27  * (at your option) any later version.
28  *
29 
30  * This program is distributed in the hope that it will be useful,
31  * but WITHOUT ANY WARRANTY; without even the implied warranty of
32  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
33  * General Public License for more details. *
34  * **************************************************************************/
35 
36 
37 
38 #ifndef RTIMER_H
39 #define RTIMER_H
40 
41 #ifdef __MINGW32__
42 
43 #include <time.h>
44 #include <stdio.h>
45 #include <string.h>
46 #include <strings.h>
47 
48 typedef struct {
49  time_t tv1, tv2;
50 } Rtimer;
51 
52 #define rt_start(rt) \
53  if((time(&(rt.tv1)) == ((time_t) -1))) { \
54  perror("time"); \
55  exit(1); \
56  }
57 
58 /* doesn't really stop, just updates endtimes */
59 #define rt_stop(rt) \
60  if((time(&(rt.tv2)) == ((time_t) -1))) { \
61  perror("time"); \
62  exit(1); \
63  }
64 
65 #define rt_u_useconds(rt) rt_w_useconds(rt)
66 
67 #define rt_s_useconds(rt) rt_w_useconds(rt)
68 
69 #define rt_w_useconds(rt) (1.0e6 * (rt.tv2 - rt.tv1))
70 
71 #else /* __MINGW32__ */
72 
73 #include <sys/time.h>
74 #include <sys/resource.h>
75 #include <stdio.h>
76 #include <string.h>
77 #include <strings.h>
78 
79 typedef struct {
80  struct rusage rut1, rut2;
81  struct timeval tv1, tv2;
82 } Rtimer;
83 
84 #define rt_start(rt) \
85  if((getrusage(RUSAGE_SELF, &rt.rut1) < 0) \
86  || (gettimeofday(&(rt.tv1), NULL) < 0)) { \
87  perror("rusage/gettimeofday"); \
88  exit(1); \
89  }
90 
91 
92 /* doesn't really stop, just updates endtimes */
93 #define rt_stop(rt) \
94  if((getrusage(RUSAGE_SELF, &rt.rut2) < 0) \
95  || (gettimeofday(&(rt.tv2), NULL) < 0)) { \
96  perror("rusage/gettimeofday"); \
97  exit(1); \
98  }
99 
100 
101 #define rt_u_useconds(rt) \
102  (((double)rt.rut2.ru_utime.tv_usec + \
103  (double)rt.rut2.ru_utime.tv_sec*1000000) \
104  - ((double)rt.rut1.ru_utime.tv_usec + \
105  (double)rt.rut1.ru_utime.tv_sec*1000000))
106 
107 #define rt_s_useconds(rt) \
108  (((double)rt.rut2.ru_stime.tv_usec + \
109  (double)rt.rut2.ru_stime.tv_sec*1000000) \
110  - ((double)rt.rut1.ru_stime.tv_usec + \
111  (double)rt.rut1.ru_stime.tv_sec*1000000))
112 
113 #define rt_w_useconds(rt) \
114  (((double)rt.tv2.tv_usec + \
115  (double)rt.tv2.tv_sec*1000000) \
116  - ((double)rt.tv1.tv_usec + \
117  (double)rt.tv1.tv_sec*1000000))
118 
119 
120 #endif /* __MINGW32__ */
121 
122 
123 
124 
125 /* not required to be called, but makes values print as 0.
126  obviously a hack */
127 #define rt_zero(rt) bzero(&(rt),sizeof(Rtimer));
128 
129 #define rt_seconds(rt) (rt_w_useconds(rt)/1000000)
130 
131 #define rt_sprint(buf, rt) rt_sprint_safe(buf,rt)
132 
133 char * rt_sprint_safe(char *buf, Rtimer rt);
134 
135 
136 #endif /* RTIMER_H */
char * rt_sprint_safe(char *buf, Rtimer rt)
Definition: rtimer.cpp:46
Definition: rtimer.h:79