source: git/Singular/timer.cc @ 551fd7

fieker-DuValspielwiese
Last change on this file since 551fd7 was 416465, checked in by Olaf Bachmann <obachman@…>, 25 years ago
* bug-fixes from work with Thomas git-svn-id: file:///usr/local/Singular/svn/trunk@3826 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 4.4 KB
RevLine 
[0e1846]1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
[416465]4/* $Id: timer.cc,v 1.13 1999-11-15 17:20:55 obachman Exp $ */
[32df82]5
[0e1846]6/*
7*  ABSTRACT - get the computing time
8*/
9
[ea986d]10#include "mod2.h"
11
[0e1846]12//the mpw timer is quite the same as the dos timer:
[1387fc6]13#ifdef __MWERKS__
[0e1846]14#define MSDOS
15#endif
16
17int        timerv = 0;
[40edb03]18static double timer_resolution = TIMER_RESOLUTION;
[ea986d]19
20static double mintime = 0.5;
21
22void SetTimerResolution(int res)
23{
24  timer_resolution = (double) res;
25}
26
27void SetMinDisplayTime(double mtime)
28{
29  mintime = mtime;
30}
31
[0e1846]32
33#ifndef MSDOS
34
35/*tested on HP9000/700, HP9000/300, Linux 0.99, SUN Sparc*/
36#include <stdio.h>
37#include <math.h>
38#include <unistd.h>
39#include <float.h>
40#include <limits.h>
41#include <sys/types.h>
[40edb03]42
43#ifdef TIME_WITH_SYS_TIME
44# include <time.h>
[b85a6c]45# ifdef HAVE_SYS_TIME_H
46#   include <sys/time.h>
47# endif
[40edb03]48#else
[b85a6c]49# ifdef HAVE_SYS_TIME_H
50#   include <sys/time.h>
[40edb03]51# else
52#   include <time.h>
53# endif
54#endif
[b85a6c]55#ifdef HAVE_SYS_TIMES_H
56#include <sys/times.h>
57#endif
58
[40edb03]59
[0e1846]60// need to be adjusted on your machine: the number of ticks per second: HZ
61#ifndef HZ
62#include <sys/param.h>
63#endif
64#if !defined(HZ) && defined(CLOCKS_PER_SEC)
65#define HZ CLOCKS_PER_SEC
66#endif
67#if !defined(HZ) && defined(CLK_TCK)
68#define HZ CLK_TCK
69#endif
70#ifndef HZ
71#ifdef sun
72#define HZ 60.0
73#else
74#define HZ 100.0
75#endif
76#endif
77
78#include "timer.h"
79#include "febase.h"
80/*3
81* the start time of the timer
82*/
83static clock_t startl;
84static clock_t siStartTime;
85
86/*3
87* temp structure to get the time
88*/
89static struct tms t_rec;
90
91/*0 implementation*/
92
93int initTimer()
94{
95  times(&t_rec);
[ed1348]96  siStartTime = t_rec.tms_utime+t_rec.tms_stime;
[0e1846]97  return (int)time(NULL);
98}
99
100void startTimer()
101{
102  times(&t_rec);
[ed1348]103  startl = t_rec.tms_utime+t_rec.tms_stime;
[0e1846]104}
105
106/*2
107* returns the time since a fixed point in seconds
108*/
109int getTimer()
110{
111  clock_t curr;
112
113  times(&t_rec);
[ed1348]114  curr = t_rec.tms_utime+t_rec.tms_stime - siStartTime;
[0e1846]115
[ea986d]116  double f =  ((double)curr) * timer_resolution / (double)HZ;
[0e1846]117  return (int)(f+0.5);
118}
119
120/*2
121* stops timer, writes string s and the time since last call of startTimer
[ea986d]122* if this time is > mintime sec
[0e1846]123*/
124void writeTime(void* v)
125{
126  clock_t curr;
127
128  times(&t_rec);
[ed1348]129  curr = t_rec.tms_utime+t_rec.tms_stime - startl;
[0e1846]130
[ea986d]131  double f =  ((double)curr) / (double)HZ;
132  if (f > mintime)
133    Print("//%s %.2f sec\n" ,v ,f);
134}
135
136#ifdef HAVE_RTIMER
137/*0 Real timer implementation*/
138int rtimerv = 0;
139static struct timeval  startRl;
140static struct timeval  siStartRTime;
141static struct timezone tzp;
142void initRTimer()
143{
144  gettimeofday(&startRl, &tzp);
[286bd57]145  gettimeofday(&siStartRTime, &tzp);
[ea986d]146}
147
148void startRTimer()
149{
150  gettimeofday(&siStartRTime, &tzp);
[0e1846]151}
[ea986d]152
153/*2
154* returns the time since a fixed point in resolutions
155*/
156int getRTimer()
157{
158  struct timeval now;
[db242b1]159
[ea986d]160  gettimeofday(&now, &tzp);
161
162  if (startRl.tv_usec > now.tv_usec)
163  {
164    now.tv_usec += 1000000;
165    now.tv_sec --;
166  }
[db242b1]167
[ea986d]168  double f =((double)  (now.tv_sec - startRl.tv_sec))*timer_resolution +
169    ((double) (now.tv_usec - startRl.tv_usec))*timer_resolution /
170    (double) 1000000;
[db242b1]171
[ea986d]172  return (int)(f+0.5);
173}
174
175/*2
176* stops timer, writes string s and the time since last call of startTimer
177* if this time is > mintime
178*/
179void writeRTime(void* v)
180{
181  struct timeval now;
182
183  gettimeofday(&now, &tzp);
184
185  if (siStartRTime.tv_usec > now.tv_usec)
186  {
187    now.tv_usec += 1000000;
188    now.tv_sec --;
189  }
[db242b1]190
[ea986d]191  double f =((double)  (now.tv_sec - siStartRTime.tv_sec)) +
192    ((double) (now.tv_usec - siStartRTime.tv_usec)) /
193    (double) 1000000;
194
195  if (f > mintime)
[db242b1]196   Print("//%s %.2f sec \n" ,v ,f);
[ea986d]197}
198#endif
199
[f988c9]200#else /* #defined MSDOS */
[0e1846]201
202/*tested on MSDOS-GCC, Macintosh*/
203#include <time.h>
204#include <stdio.h>
205#include <math.h>
206#include <float.h>
207
208#include "timer.h"
209#include "febase.h"
210
211/*3
212* the start time of the timer
213*/
214static clock_t startl;
215static clock_t siStartTime;
216
217/*2
218* starts the timer; used with getTime
219*/
220int initTimer()
221{
222  siStartTime = clock();
223  return (int)siStartTime;
224}
225
226/*2
227* starts the timer; used with writeTime
228*/
229void startTimer()
230{
231  startl = clock();
232}
233
234/*2
235* returns the time since a fixed point in seconds
236*/
237int getTimer()
238{
239  clock_t curr = clock() - siStartTime;
[ea986d]240  double f =  ((double)curr)*timer_resolution/ (double)CLOCKS_PER_SEC;
[0e1846]241  return (int)(f+0.5);
242}
243/*2
244* stops timer, writes string s and the time since last call of startTimer
245* if this time is > 0.5 sec
246*/
247void writeTime(void* v)
248{
249  clock_t curr = clock() - startl;
250  double f =  ((double)curr) / CLOCKS_PER_SEC;
[ea986d]251  if (f > mintime)
252    Print("//%s %.1f sec\n" ,v ,f);
[0e1846]253}
[f988c9]254#endif /* MSDOS */
Note: See TracBrowser for help on using the repository browser.