source: trunk/Softwares/Dhrystone/src/c/dtime.c @ 114

Last change on this file since 114 was 114, checked in by rosiere, 15 years ago

1) Fix bug with previous commit
2) Add test libc
3) Change Dhrystone

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