GRASS 8 Programmer's Manual 8.6.0dev(2026)-f6f2c534ea
Loading...
Searching...
No Matches
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#ifndef RTIMER_H
37#define RTIMER_H
38
39#ifdef _WIN32
40
41#include <time.h>
42#include <stdio.h>
43#include <string.h>
44#ifdef __MINGW32__
45#include <strings.h>
46#endif
47typedef struct {
48 time_t tv1, tv2;
49} Rtimer;
50
51#define rt_start(rt) \
52 if ((time(&(rt.tv1)) == ((time_t)-1))) { \
53 perror("time"); \
54 exit(1); \
55 }
56
57/* doesn't really stop, just updates endtimes */
58#define rt_stop(rt) \
59 if ((time(&(rt.tv2)) == ((time_t)-1))) { \
60 perror("time"); \
61 exit(1); \
62 }
63
64#define rt_u_useconds(rt) rt_w_useconds(rt)
65
66#define rt_s_useconds(rt) rt_w_useconds(rt)
67
68#define rt_w_useconds(rt) (1.0e6 * (rt.tv2 - rt.tv1))
69
70#else /* __MINGW32__ */
71
72#include <sys/time.h>
73#include <sys/resource.h>
74#include <stdio.h>
75#include <string.h>
76#include <strings.h>
77
78typedef struct {
79 struct rusage rut1, rut2;
80 struct timeval tv1, tv2;
81} Rtimer;
82
83#define rt_start(rt) \
84 if ((getrusage(RUSAGE_SELF, &rt.rut1) < 0) || \
85 (gettimeofday(&(rt.tv1), NULL) < 0)) { \
86 perror("rusage/gettimeofday"); \
87 exit(1); \
88 }
89
90/* doesn't really stop, just updates endtimes */
91#define rt_stop(rt) \
92 if ((getrusage(RUSAGE_SELF, &rt.rut2) < 0) || \
93 (gettimeofday(&(rt.tv2), NULL) < 0)) { \
94 perror("rusage/gettimeofday"); \
95 exit(1); \
96 }
97
98#define rt_u_useconds(rt) \
99 (((double)rt.rut2.ru_utime.tv_usec + \
100 (double)rt.rut2.ru_utime.tv_sec * 1000000) - \
101 ((double)rt.rut1.ru_utime.tv_usec + \
102 (double)rt.rut1.ru_utime.tv_sec * 1000000))
103
104#define rt_s_useconds(rt) \
105 (((double)rt.rut2.ru_stime.tv_usec + \
106 (double)rt.rut2.ru_stime.tv_sec * 1000000) - \
107 ((double)rt.rut1.ru_stime.tv_usec + \
108 (double)rt.rut1.ru_stime.tv_sec * 1000000))
109
110#define rt_w_useconds(rt) \
111 (((double)rt.tv2.tv_usec + (double)rt.tv2.tv_sec * 1000000) - \
112 ((double)rt.tv1.tv_usec + (double)rt.tv1.tv_sec * 1000000))
113
114#endif /* __MINGW32__ */
115
116/* not required to be called, but makes values print as 0.
117 obviously a hack */
118#define rt_zero(rt) bzero(&(rt), sizeof(Rtimer));
119
120#define rt_seconds(rt) (rt_w_useconds(rt) / 1000000)
121
122#define rt_sprint(buf, rt) rt_sprint_safe(buf, rt)
123
124char *rt_sprint_safe(char *buf, Rtimer rt);
125
126#endif /* RTIMER_H */
char * rt_sprint_safe(char *buf, Rtimer rt)
Definition rtimer.cpp:42