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