My Project
Loading...
Searching...
No Matches
timer.cc
Go to the documentation of this file.
1/****************************************
2* Computer Algebra System SINGULAR *
3****************************************/
4
5/*
6* ABSTRACT - get the computing time
7*/
8
9
10
11
12#include "kernel/mod2.h"
13
14#include <sys/resource.h>
15#include <unistd.h>
16
17VAR int timerv = 0;
19
20STATIC_VAR double mintime = 0.5;
21
23{
24 timer_resolution = (double) res;
25}
26
27void SetMinDisplayTime(double mtime)
28{
29 mintime = mtime;
30}
31
32#include <stdio.h>
33
34#ifdef TIME_WITH_SYS_TIME
35# include <time.h>
36# ifdef HAVE_SYS_TIME_H
37# include <sys/time.h>
38# endif
39#else
40# ifdef HAVE_SYS_TIME_H
41# include <sys/time.h>
42# else
43# include <time.h>
44# endif
45#endif
46
47#ifdef HAVE_SYS_TIMES_H
48#include <sys/times.h>
49#endif
50
51
52#include "reporter/reporter.h"
54
55/*3
56* the start time of the timer
57*/
59
60/*3
61* temp structure to get the time
62*/
63STATIC_VAR struct rusage t_rec;
64/*0 implementation*/
65
67{
68 getrusage(RUSAGE_SELF,&t_rec);
69 siStartTime = (int64)t_rec.ru_utime.tv_sec*1000000+(int64)t_rec.ru_utime.tv_usec
70 +(int64)t_rec.ru_stime.tv_sec*1000000+(int64)t_rec.ru_stime.tv_usec;
71 getrusage(RUSAGE_CHILDREN,&t_rec);
72 siStartTime += (int64)t_rec.ru_utime.tv_sec*1000000+(int64)t_rec.ru_utime.tv_usec
73 +(int64)t_rec.ru_stime.tv_sec*1000000+(int64)t_rec.ru_stime.tv_usec;
74 return (int)time(NULL);
75}
76
77/*2
78* returns the time since a fixed point in seconds
79*/
81{
82 int64 curr;
83 getrusage(RUSAGE_SELF,&t_rec);
84 curr = (int64)t_rec.ru_utime.tv_sec*1000000+(int64)t_rec.ru_utime.tv_usec
85 +(int64)t_rec.ru_stime.tv_sec*1000000+(int64)t_rec.ru_stime.tv_usec;
86 getrusage(RUSAGE_CHILDREN,&t_rec);
87 curr += (int64)t_rec.ru_utime.tv_sec*1000000+(int64)t_rec.ru_utime.tv_usec
88 +(int64)t_rec.ru_stime.tv_sec*1000000+(int64)t_rec.ru_stime.tv_usec;
89 double f = ((double)curr) * timer_resolution / (double)1000000;
90 return (long)(f+0.5);
91}
92
93/*2
94* stops timer, writes string s and the time since last call of startTimer
95* if this time is > mintime sec
96*/
97#ifdef EXTEND_TIMER_D
99#endif
100
101void writeTime(const char* v)
102{
103 int64 curr;
104 getrusage(RUSAGE_SELF,&t_rec);
105 curr = (int64)t_rec.ru_utime.tv_sec*1000000+(int64)t_rec.ru_utime.tv_usec
106 +(int64)t_rec.ru_stime.tv_sec*1000000+(int64)t_rec.ru_stime.tv_usec;
107 getrusage(RUSAGE_CHILDREN,&t_rec);
108 curr += (int64)t_rec.ru_utime.tv_sec*1000000+(int64)t_rec.ru_utime.tv_usec
109 +(int64)t_rec.ru_stime.tv_sec*1000000+(int64)t_rec.ru_stime.tv_usec;
110 curr -= siStartTime;
111 double f = ((double)curr) * timer_resolution / (double)1000000;
113 {
114#ifdef EXTEND_TIMER_D
115 Print("//%s %.2f/%d sec (%d) >>%s<<\n" ,v ,f,(int)timer_resolution,iiOp,my_yylinebuf);
116#else
117 if (timer_resolution==(double)1.0)
118 Print("//%s %.2f sec\n" ,v ,f);
119 else
120 Print("//%s %.2f/%d sec\n" ,v ,f,(int)timer_resolution);
121#endif
122 }
123}
124
125/*0 Real timer implementation*/
126VAR int rtimerv = 0;
127STATIC_VAR struct timeval startRl;
129STATIC_VAR struct timezone tzp;
130
132{
133 gettimeofday(&siStartRTime, &tzp);
134}
135
137{
138#ifdef HAVE_GETTIMEOFDAY
139 gettimeofday(&startRl, &tzp);
140 gettimeofday(&siStartRTime, &tzp);
141#else
142 memset(&startRl,0,sizeof(startRl));
143 memset(&siStartRTime,0,sizeof(siStartRTime));
144#endif
145}
146
147/*2
148* returns the time since a fixed point in resolutions
149*/
151{
152 struct timeval now;
153
154 gettimeofday(&now, &tzp);
155
156 if (startRl.tv_usec > now.tv_usec)
157 {
158 now.tv_usec += 1000000;
159 now.tv_sec --;
160 }
161
162 double f =((double) (now.tv_sec - startRl.tv_sec))*timer_resolution +
163 ((double) (now.tv_usec - startRl.tv_usec))*timer_resolution /
164 (double) 1000000;
165
166 return (int)(f+0.5);
167}
168
169/*2
170* stops timer, writes string s and the time since last call of startTimer
171* if this time is > mintime
172*/
173void writeRTime(const char* v)
174{
175 struct timeval now;
176
177 gettimeofday(&now, &tzp);
178
179 if (siStartRTime.tv_usec > now.tv_usec)
180 {
181 now.tv_usec += 1000000;
182 now.tv_sec --;
183 }
184
185 double f =((double) (now.tv_sec - siStartRTime.tv_sec)) +
186 ((double) (now.tv_usec - siStartRTime.tv_usec)) /
187 (double) 1000000;
188
189 if (f > mintime)
190 Print("//%s %.2f sec \n" ,v ,f);
191}
long int64
Definition auxiliary.h:68
FILE * f
Definition checklibs.c:9
#define Print
Definition emacs.cc:80
CanonicalForm res
Definition facAbsFact.cc:60
const Variable & v
< [in] a sqrfree bivariate poly
Definition facBivar.h:39
VAR char my_yylinebuf[80]
Definition febase.cc:44
#define STATIC_VAR
Definition globaldefs.h:7
#define EXTERN_VAR
Definition globaldefs.h:6
#define VAR
Definition globaldefs.h:5
VAR int iiOp
Definition iparith.cc:218
#define TIMER_RESOLUTION
Definition mod2.h:35
#define NULL
Definition omList.c:12
void writeRTime(const char *v)
Definition timer.cc:173
void SetMinDisplayTime(double mtime)
Definition timer.cc:27
int startTimer()
Definition timer.cc:66
STATIC_VAR struct timeval siStartRTime
Definition timer.cc:128
STATIC_VAR double mintime
Definition timer.cc:20
void initRTimer()
Definition timer.cc:136
STATIC_VAR double timer_resolution
Definition timer.cc:18
STATIC_VAR struct timeval startRl
Definition timer.cc:127
int getRTimer()
Definition timer.cc:150
long getTimer()
Definition timer.cc:80
STATIC_VAR struct rusage t_rec
Definition timer.cc:63
STATIC_VAR int64 siStartTime
Definition timer.cc:58
VAR int rtimerv
Definition timer.cc:126
STATIC_VAR struct timezone tzp
Definition timer.cc:129
void writeTime(const char *v)
Definition timer.cc:101
VAR int timerv
Definition timer.cc:17
void SetTimerResolution(int res)
Definition timer.cc:22
void startRTimer()
Definition timer.cc:131