source: trunk/Softwares/Basic_test/src/c/timers_b.c @ 105

Last change on this file since 105 was 81, checked in by rosiere, 17 years ago
  • Finish Environment (and test)
  • Continue predictor_unit
  • Add external tools
  • svn keyword "Id" set
  • Property svn:keywords set to Id
File size: 10.5 KB
Line 
1/*****************************************************/
2/* Various timer routines.                           */
3/* Al Aburto, aburto@nosc.mil, 18 Feb 1997           */
4/*                                                   */
5/* t = dtime() outputs the current time in seconds.  */
6/* Use CAUTION as some of these routines will mess   */
7/* up when timing across the hour mark!!!            */
8/*                                                   */
9/* For timing I use the 'user' time whenever         */
10/* possible. Using 'user+sys' time is a separate     */
11/* issue.                                            */
12/*                                                   */
13/* Example Usage:                                    */
14/* [timer options added here]                        */
15/* main()                                            */
16/* {                                                 */
17/* double starttime,benchtime,dtime();               */
18/*                                                   */
19/* starttime = dtime();                              */ 
20/* [routine to time]                                 */
21/* benchtime = dtime() - starttime;                  */
22/* }                                                 */
23/*                                                   */
24/* [timer code below added here]                     */
25/*****************************************************/
26
27/***************************************************************/
28/* Timer options. You MUST uncomment one of the options below  */
29/* or compile, for example, with the '-DUNIX' option.          */
30/***************************************************************/
31/* #define Amiga       */
32/* #define UNIX        */
33/* #define UNIX_Old    */
34/* #define VMS         */
35/* #define BORLAND_C   */
36/* #define MSC         */
37/* #define MAC         */
38/* #define IPSC        */
39/* #define FORTRAN_SEC */
40/* #define GTODay      */
41/* #define CTimer      */
42/* #define UXPM        */
43/* #define MAC_TMgr    */
44/* #define PARIX       */
45/* #define POSIX       */
46/* #define WIN32       */
47/* #define POSIX1      */
48/***********************/
49
50/*********************************/
51/* Timer code.                   */
52/*********************************/
53
54/***************************************************/
55/*  SIM2OS dtime().                                */
56/***************************************************/
57#ifdef SIM2OS
58
59#include <time.h>
60#include "dhry.h"
61#include "service_clock.h"
62
63#ifndef MHZ
64#define MHZ (1000000)
65#endif //!MHZ
66
67#ifndef FRQ
68#define FRQ (1*MHZ)
69#endif //!FRQ
70
71DOUBLE dtime()
72{
73  DOUBLE         dtime;
74
75  dtime = (DOUBLE)(service_clock())/(DOUBLE)FRQ;
76 
77  return (dtime);
78}
79#endif
80
81/*******************/
82/*  Amiga dtime()  */
83/*******************/
84#ifdef Amiga
85#include <ctype.h>
86#define HZ 50
87
88double dtime()
89{
90 double q;
91
92 struct tt
93       {
94        long  days;
95        long  minutes;
96        long  ticks;
97       } tt;
98
99 DateStamp(&tt);
100
101 q = ((double)(tt.ticks + (tt.minutes * 60L * 50L))) / (double)HZ;
102
103 return q;
104}
105#endif
106
107/*****************************************************/
108/*  UNIX dtime(). This is the preferred UNIX timer.  */
109/*  Provided by: Markku Kolkka, mk59200@cc.tut.fi    */
110/*  HP-UX Addition by: Bo Thide', bt@irfu.se         */
111/*****************************************************/
112#ifdef UNIX
113#include <sys/time.h>
114#include <sys/resource.h>
115
116#ifdef hpux
117#include <sys/syscall.h>
118#define getrusage(a,b) syscall(SYS_getrusage,a,b)
119#endif
120
121struct rusage rusage;
122
123double dtime()
124{
125 double q;
126 getrusage(RUSAGE_SELF,&rusage);
127 q = (double)(rusage.ru_utime.tv_sec);
128 q = q + (double)(rusage.ru_utime.tv_usec) * 1.0e-06;
129 return q;
130}
131#endif
132
133/***************************************************/
134/*  UNIX_Old dtime(). This is the old UNIX timer.  */
135/*  Make sure HZ is properly defined in param.h !! */
136/***************************************************/
137#ifdef UNIX_Old
138#include <sys/types.h>
139#include <sys/times.h>
140#include <sys/param.h>
141
142#ifndef HZ
143#define HZ 60
144#endif
145
146struct tms tms;
147
148double dtime()
149{
150 double q;
151
152 times(&tms);
153
154 q = (double)(tms.tms_utime) / (double)HZ;
155       
156 return q;
157}
158#endif
159
160/*********************************************************/
161/*  VMS dtime() for VMS systems.                         */
162/*  Provided by: RAMO@uvphys.phys.UVic.CA                */
163/*  Some people have run into problems with this timer.  */
164/*********************************************************/
165#ifdef VMS
166#include time
167
168#ifndef HZ
169#define HZ 100
170#endif
171
172struct tbuffer_t
173      {
174       int proc_user_time;
175       int proc_system_time;
176       int child_user_time;
177       int child_system_time;
178      };
179
180struct tbuffer_t tms;
181
182double dtime()
183{
184 double q;
185
186 times(&tms);
187
188 q = (double)(tms.proc_user_time) / (double)HZ;
189       
190 return q;
191}
192#endif
193
194/******************************/
195/*  BORLAND C dtime() for DOS */
196/******************************/
197#ifdef BORLAND_C
198#include <ctype.h>
199#include <dos.h>
200#include <time.h>
201
202#define HZ 100
203struct time tnow;
204
205double dtime()
206{
207 double q;
208
209 gettime(&tnow);
210
211 q = 60.0 * (double)(tnow.ti_min);
212 q = q + (double)(tnow.ti_sec);
213 q = q + (double)(tnow.ti_hund)/(double)HZ;
214       
215 return q;
216}
217#endif
218
219/**************************************/
220/*  Microsoft C (MSC) dtime() for DOS */
221/**************************************/
222#ifdef MSC
223#include <time.h>
224#include <ctype.h>
225
226#define HZ CLOCKS_PER_SEC
227clock_t tnow;
228
229double dtime()
230{
231 double q;
232
233 tnow = clock();
234
235 q = (double)tnow / (double)HZ;
236       
237 return q;
238}
239#endif
240
241/*************************************/
242/*  Macintosh (MAC) Think C dtime()  */
243/*************************************/
244#ifdef MAC
245#include <time.h>
246
247#define HZ 60
248
249double dtime()
250{
251 double q;
252
253 q = (double)clock() / (double)HZ;
254       
255 return q;
256}
257#endif
258
259/************************************************************/
260/*  iPSC/860 (IPSC) dtime() for i860.                       */
261/*  Provided by: Dan Yergeau, yergeau@gloworm.Stanford.EDU  */
262/************************************************************/
263#ifdef IPSC
264extern double dclock();
265
266double dtime()
267{
268 double q;
269
270 q = dclock();
271       
272 return q;
273}
274#endif
275
276/**************************************************/
277/*  FORTRAN dtime() for Cray type systems.        */
278/*  This is the preferred timer for Cray systems. */
279/**************************************************/
280#ifdef FORTRAN_SEC
281
282fortran double second();
283
284double dtime()
285{
286 double q;
287
288 second(&q);
289       
290 return q;
291}
292#endif
293
294/***********************************************************/
295/*  UNICOS C dtime() for Cray UNICOS systems.  Don't use   */
296/*  unless absolutely necessary as returned time includes  */
297/*  'user+system' time.  Provided by: R. Mike Dority,      */
298/*  dority@craysea.cray.com                                */
299/***********************************************************/
300#ifdef CTimer
301#include <time.h>
302
303double dtime()
304{
305 double    q;
306 clock_t   clock(void);
307
308 q = (double)clock() / (double)CLOCKS_PER_SEC;
309
310 return q;
311}
312#endif
313
314/********************************************/
315/* Another UNIX timer using gettimeofday(). */
316/* However, getrusage() is preferred.       */
317/********************************************/
318#ifdef GTODay
319#include <sys/time.h>
320
321struct timeval tnow;
322
323double dtime()
324{
325 double q;
326
327 gettimeofday(&tnow,NULL);
328 q = (double)tnow.tv_sec + (double)tnow.tv_usec * 1.0e-6;
329
330 return q;
331}
332#endif
333
334/*****************************************************/
335/*  Fujitsu UXP/M timer.                             */
336/*  Provided by: Mathew Lim, ANUSF, M.Lim@anu.edu.au */
337/*****************************************************/
338#ifdef UXPM
339#include <sys/types.h>
340#include <sys/timesu.h>
341struct tmsu rusage;
342
343double dtime()
344{
345 double q;
346
347 timesu(&rusage);
348
349 q = (double)(rusage.tms_utime) * 1.0e-06;
350       
351 return q;
352}
353#endif
354
355/**********************************************/
356/*    Macintosh (MAC_TMgr) Think C dtime()    */
357/*   requires Think C Language Extensions or  */
358/*    #include <MacHeaders> in the prefix     */
359/*  provided by Francis H Schiffer 3rd (fhs)  */
360/*         skipschiffer@genie.geis.com        */
361/**********************************************/
362#ifdef MAC_TMgr
363#include <Timer.h>
364#include <stdlib.h>
365
366static TMTask   mgrTimer;
367static Boolean  mgrInited = false;
368static double   mgrClock;
369
370#define RMV_TIMER RmvTime( (QElemPtr)&mgrTimer )
371#define MAX_TIME  1800000000L
372/* MAX_TIME limits time between calls to */
373/* dtime( ) to no more than 30 minutes   */
374/* this limitation could be removed by   */
375/* creating a completion routine to sum  */
376/* 30 minute segments (fhs 1994 feb 9)   */
377
378static void Remove_timer( )
379{
380 RMV_TIMER;
381 mgrInited = false;
382}
383
384double  dtime( )
385{
386 if( mgrInited ) {
387   RMV_TIMER;
388   mgrClock += (MAX_TIME + mgrTimer.tmCount)*1.0e-6;
389 } else {
390   if( _atexit( &Remove_timer ) == 0 ) mgrInited = true;
391   mgrClock = 0.0;
392 }
393 
394 if ( mgrInited )
395   {
396    mgrTimer.tmAddr = NULL;
397    mgrTimer.tmCount = 0;
398    mgrTimer.tmWakeUp = 0;
399    mgrTimer.tmReserved = 0;
400    InsTime( (QElemPtr)&mgrTimer );
401    PrimeTime( (QElemPtr)&mgrTimer, -MAX_TIME );
402   }
403 return( mgrClock );
404}
405#endif
406
407/***********************************************************/
408/*  Parsytec GCel timer.                                   */
409/*  Provided by: Georg Wambach, gw@informatik.uni-koeln.de */
410/***********************************************************/
411#ifdef PARIX
412#include <sys/time.h>
413
414double dtime()
415{
416 double q;
417
418 q = (double) (TimeNowHigh()) / (double) CLK_TCK_HIGH;
419
420 return q;
421}
422#endif
423
424/************************************************/
425/*  Sun Solaris POSIX dtime() routine           */
426/*  Provided by: Case Larsen, CTLarsen.lbl.gov  */
427/************************************************/
428#ifdef POSIX
429#include <sys/time.h>
430#include <sys/resource.h>
431#include <sys/rusage.h>
432
433#ifdef __hpux
434#include <sys/syscall.h>
435#endif
436
437struct rusage rusage;
438
439double dtime()
440{
441 double q;
442
443 getrusage(RUSAGE_SELF,&rusage);
444
445 q = (double)(rusage.ru_utime.tv_sec);
446 q = q + (double)(rusage.ru_utime.tv_nsec) * 1.0e-09;
447       
448 return q;
449}
450#endif
451
452
453/****************************************************/
454/*  Windows NT (32 bit) dtime() routine             */
455/*  Provided by: Piers Haken, piersh@microsoft.com  */
456/****************************************************/
457#ifdef WIN32
458#include <windows.h>
459
460double dtime(void)
461{
462 double q;
463
464 q = (double)GetTickCount() * 1.0e-03;
465       
466 return q;
467}
468#endif
469
470/*****************************************************/
471/* Time according to POSIX.1  -  <J.Pelan@qub.ac.uk> */
472/* Ref: "POSIX Programmer's Guide"  O'Reilly & Assoc.*/
473/*****************************************************/
474#ifdef POSIX1
475#define _POSIX_SOURCE 1
476#include <unistd.h>
477#include <limits.h>
478#include <sys/times.h>
479
480struct tms tms;
481
482double dtime()
483{
484 double q;
485 times(&tms);
486 q = (double)tms.tms_utime / (double)CLK_TCK;
487 return q;
488}
489#endif
Note: See TracBrowser for help on using the repository browser.