home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / fortran / library / whets / test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-05  |  982 b   |  57 lines

  1. double second_();
  2.  
  3.  
  4.  
  5. main ()
  6.  
  7. {
  8.  
  9.     int i;
  10.  
  11.     double f1,f2,f3,f4;
  12.  
  13.  
  14.  
  15.     f2 = 2345.2345;
  16.  
  17.     f3 = 4536.5467;
  18.  
  19.     f4 = 2435.9788;
  20.  
  21.     
  22.  
  23.     for (i=0;i<1000000;i++) {
  24.  
  25.         f1 = f2 * f3 / f4;
  26.  
  27.     }
  28.  
  29.  
  30.  
  31.     printf("second()=%20.10e\n\n",(double)second_());
  32.  
  33. }
  34.  
  35.  
  36.  
  37.  
  38.  
  39. #ifdef UCB
  40.  
  41. #include <sys/time.h>
  42.  
  43. #include <sys/resource.h>
  44.  
  45.  
  46.  
  47. double
  48.  
  49. second_ ()
  50.  
  51. {
  52.  
  53.     struct rusage ru;
  54.  
  55.  
  56.  
  57. #ifdef MOXIE
  58.  
  59.     static unsigned count = 0;
  60.  
  61.     static unsigned stop;
  62.  
  63.     extern unsigned __Argc;
  64.  
  65.     extern char **__Argv;
  66.  
  67.     if (count == 0 && __Argc > 1) {
  68.  
  69.     stop = atoi(__Argv[__Argc-1]);
  70.  
  71.     }
  72.  
  73.     count += 1;
  74.  
  75.     if (count == stop) exit(0);
  76.  
  77. #endif
  78.  
  79.  
  80.  
  81.     getrusage (0, &ru);
  82.  
  83.     return ((double)ru.ru_utime.tv_sec + ((double)ru.ru_utime.tv_usec / 1.0e6));
  84.  
  85. }
  86.  
  87. #else
  88.  
  89.  
  90.  
  91. #include <sys/types.h>
  92.  
  93. #include <sys/times.h>
  94.  
  95. double
  96.  
  97. second_()
  98.  
  99. {
  100.  
  101.     struct tms buf;
  102.  
  103.     long t;
  104.  
  105.     t = times(&buf);
  106.  
  107.     return(buf.tms_utime*0.01);         /* 1 tick = 1/100 sec */
  108.  
  109. }
  110.  
  111. #endif
  112.  
  113.