1 /**********************************************************/
2 /* Date: Mon, 10 Mar 1997 07:38:18 -0500 */
3 /* From: Roy Longbottom <Roy_Longbottom@compuserve.com> */
4 /* Subject: WHET02.txt */
5 /* To: "Alfred A. Aburto Jr." <aburto@cts.com> */
6 /**********************************************************/
9 * C/C++ Whetstone Benchmark Single or Double Precision
11 * Original concept Brian Wichmann NPL 1960's
12 * Original author Harold Curnow CCTA 1972
13 * Self timing versions Roy Longbottom CCTA 1978/87
14 * Optimisation control Bangor University 1987/90
15 * C/C++ Version Roy Longbottom 1996
16 * Compatibility & timers Al Aburto 1996
18 ************************************************************
20 * Official version approved by:
22 * Harold Curnow 100421.1615@compuserve.com
24 * Happy 25th birthday Whetstone, 21 November 1997
26 ************************************************************
28 * The program normally runs for about 100 seconds
29 * (adjustable in main - variable duration). This time
30 * is necessary because of poor PC clock resolution.
31 * The original concept included such things as a given
32 * number of subroutine calls and divides which may be
33 * changed by optimisation. For comparison purposes the
34 * compiler and level of optimisation should be identified.
36 ************************************************************
38 * The original benchmark had a single variable I which
39 * controlled the running time. Constants with values up
40 * to 899 were multiplied by I to control the number
41 * passes for each loop. It was found that large values
42 * of I could overflow index registers so an extra outer
43 * loop with a second variable J was added.
45 * Self timing versions were produced during the early
46 * days. The 1978 changes supplied timings of individual
47 * loops and these were used later to produce MFLOPS and
50 * 1987 changes converted the benchmark to Fortran 77
51 * standards and removed redundant IF statements and
52 * loops to leave the 8 active loops N1 to N8. Procedure
53 * P3 was changed to use global variables to avoid over-
54 * optimisation with the first two statements changed from
55 * X1=X and Y1=Y to X=Y and Y=Z. A self time calibrating
56 * version for PCs was also produced, the facility being
57 * incorporated in this version.
59 * This version has changes to avoid worse than expected
60 * speed ratings, due to underflow, and facilities to show
61 * that consistent numeric output is produced with varying
62 * optimisation levels or versions in different languages.
64 * Some of the procedures produce ever decreasing numbers.
65 * To avoid problems, variables T and T1 have been changed
66 * from 0.499975 and 0.50025 to 0.49999975 and 0.50000025.
68 * Each section now has its own double loop. Inner loops
69 * are run 100 times the loop constants. Calibration
70 * determines the number of outer loop passes. The
71 * numeric results produced in the main output are for
72 * one pass on the outer loop. As underflow problems were
73 * still likely on a processor 100 times faster than a 100
74 * MHZ Pentium, three sections have T=1.0-T inserted in the
75 * outer loop to avoid the problem. The two loops avoid
76 * index register overflows.
78 * The first section is run ten times longer than required
79 * for accuracy in calculating MFLOPS. This time is divided
80 * by ten for inclusion in the MWIPS calculations.
82 * This version has facilities for typing in details of the
83 * particular run. This information is appended to file
84 * whets.res along with the results. The input section can
85 * be avoided using a command line parameter N (for example
88 * Roy Longbottom 101323.2241@compuserve.com
90 ************************************************************
92 * Whetstone benchmark results are available in whets.tbl
93 * from ftp.nosc.mil/pub/aburto. The results include
94 * further details of the benchmarks.
96 ************************************************************
98 * Source code is available in C/C++, Fortran, Basic and
99 * Visual Basic in the same format as this version. Pre-
100 * compiled versions for PCs are also available via C++.
101 * These comprise optimised and non-optimised versions
102 * for DOS, Windows and NT.
104 * This version compiles and runs correctly either as a
105 * C or CPP program with a WATCOM and Borland compiler.
107 ************************************************************
109 * Example of initial calibration display (Pentium 100 MHz)
111 * Single Precision C/C++ Whetstone Benchmark
114 * 0.17 Seconds 1 Passes (x 100)
115 * 0.77 Seconds 5 Passes (x 100)
116 * 3.70 Seconds 25 Passes (x 100)
118 * Use 676 passes (x 100)
120 * 676 passes are used for an approximate duration of 100
121 * seconds, providing an initial estimate of a speed rating
124 * This is followed by the table of results as below. Input
125 * statements are then supplied to type in the run details.
127 ************************************************************
129 * Examples of results from file whets.res
131 * Whetstone Single Precision Benchmark in C/C++
138 * H/W Options Neptune chipset
140 * Compiler Watcom C/C++ 10.5 Win386
141 * Options No optimisation
142 * Run by Roy Longbottom
144 * Mail 101323.2241@compuserve.com
146 * Loop content Result MFLOPS MOPS Seconds
148 * N1 floating point -1.12475025653839100 19.971 0.274
149 * N2 floating point -1.12274754047393800 11.822 3.240
150 * N3 if then else 1.00000000000000000 11.659 2.530
151 * N4 fixed point 12.00000000000000000 13.962 6.430
152 * N5 sin,cos etc. 0.49904659390449520 2.097 11.310
153 * N6 floating point 0.99999988079071040 3.360 45.750
154 * N7 assignments 3.00000000000000000 2.415 21.810
155 * N8 exp,sqrt etc. 0.75110864639282230 1.206 8.790
157 * MWIPS 28.462 100.134
159 * Whetstone Single Precision Benchmark in C/C++
161 * Compiler Watcom C/C++ 10.5 Win386
162 * Options -otexan -zp4 -om -fp5 -5r
164 * Loop content Result MFLOPS MOPS Seconds
166 * N1 floating point -1.12475025653839100 26.751 0.478
167 * N2 floating point -1.12274754047393800 17.148 5.220
168 * N3 if then else 1.00000000000000000 19.922 3.460
169 * N4 fixed point 12.00000000000000000 15.978 13.130
170 * N5 sin,cos etc. 0.49904659390449520 2.663 20.810
171 * N6 floating point 0.99999988079071040 10.077 35.650
172 * N7 assignments 3.00000000000000000 22.877 5.380
173 * N8 exp,sqrt etc. 0.75110864639282230 1.513 16.370
175 * MWIPS 66.270 100.498
178 * Whetstone Double Precision Benchmark in C/C++
180 * Compiler Watcom C/C++ 10.5 Win32NT
181 * Options -otexan -zp4 -om -fp5 -5r
183 * Loop content Result MFLOPS MOPS Seconds
185 * N1 floating point -1.12398255667391900 26.548 0.486
186 * N2 floating point -1.12187079889284400 16.542 5.460
187 * N3 if then else 1.00000000000000000 19.647 3.540
188 * N4 fixed point 12.00000000000000000 15.680 13.500
189 * N5 sin,cos etc. 0.49902937281515140 3.019 18.520
190 * N6 floating point 0.99999987890802820 9.977 36.330
191 * N7 assignments 3.00000000000000000 22.620 5.490
192 * N8 exp,sqrt etc. 0.75100163018457870 1.493 16.740
194 * MWIPS 67.156 100.066
196 * Note different numeric results to single precision. Slight variations
197 * are normal with different compilers and sometimes optimisation levels.
200 * Example Single Precision Optimised Results
202 * MWIPS MFLOPS MFLOPS MFLOPS COS EXP FIXPT IF EQUAL
203 * PC 1 2 3 MOPS MOPS MOPS MOPS MOPS
205 * P3 5.68 0.928 0.884 0.673 0.461 0.275 2.36 2.16 0.638
206 * P4 16.4 5.09 4.03 2.66 0.526 0.342 6.36 6.00 5.28
207 * P5 66.3 26.8 17.1 10.1 2.66 1.51 16.0 19.9 22.9
208 * P6 161 50.3 45.2 31.5 4.46 2.77 102 20.6 119
210 * Example Single Precision Non-optimised Results
212 * P3 3.07 0.860 0.815 0.328 0.355 0.160 1.70 1.32 0.264
213 * P4 10.0 4.68 3.51 1.27 0.482 0.298 5.73 5.20 1.18
214 * P5 28.5 20.0 11.8 3.36 2.10 1.21 14.0 11.7 2.42
215 * P6 81.7 47.5 37.8 10.9 3.91 2.43 51.2 42.8 7.85
217 * Summary results as in whets.tbl at ftp.nosc.mil/pub/aburto
219 * MFLOPS = Geometric Mean of three MFLOPS loops
220 * VAX MIPS = 5 * Geometric Mean of last three items above
223 * PC System CPU/Options Cache MHz MWIPS MFLOPS MIPS
225 * P3 Clone AM80386DX with 387 128K 40 5.68 0.820 7.40
226 * P4 Escom 80486DX2 CIS chipset 128K 66 16.4 3.79 29.3
227 * P5 Escom Pentium Neptune chipset 256K 100 66.3 16.7 96.9
228 * P6 Dell PentiumPro 440FX PCIset 256K 200 161 41.5 315
230 * P3 Clone AM80386DX with 387 128K 40 3.07 0.613 4.20
231 * P4 Escom 80486DX2 CIS chipset 128K 66 10.0 2.75 16.4
232 * P5 Escom Pentium Neptune chipset 256K 100 28.5 9.26 36.6
233 * P6 Dell PentiumPro 440FX PCIset 256K 200 81.7 26.9 129
235 **************************************************************************
237 * Running In fprintf(stderr,"TIMEBASE|60\n");
240 * 1. In order to compile successfully, include timer option as
242 * 2. If pre-compiled codes are to be distributed, compile with the
243 * -DPRECOMP option or uncomment #define PRECOMP at PRECOMPILE
244 * below. Also insert compiler name and optimisation details
245 * at #define precompiler and #define preoptions.
246 * 3. Compile and run for single precision results. Include run
247 * time parameter N to bipass typing in hardware details etc.
248 * 4. Compile with -DDP option or uncomment #define DP at PRECISION
249 * below and run for double precision results.
250 * 5. Run with maximum and no optimisation (minimum debug)
251 * 6. Notify Roy Longbottom of other necessary changes
252 * 7. Send results file whets.res to Roy Longbottom - with one
253 * sample of each run and system details fully completed
255 * Roy Longbottom 101323.2241@compuserve.com 6 November 1996
257 **************************************************************************
260 #include <math.h> /* for sin, exp etc. */
261 #include <stdio.h> /* standard I/O */
262 #include <string.h> /* for strcpy - 3 occurrences */
263 #include <stdlib.h> /* for exit - 1 occurrence */
265 /***************************************************************/
266 /* Timer options. You MUST uncomment one of the options below */
267 /* or compile, for example, with the '-DUNIX' option. */
268 /***************************************************************/
271 /* #define UNIX_Old */
273 /* #define BORLAND_C */
277 /* #define FORTRAN_SEC */
281 /* #define MAC_TMgr */
286 /***********************/
288 /*PRECISION PRECISION PRECISION PRECISION PRECISION PRECISION PRECISION*/
294 #define Precision "Double"
297 #define Precision "Single"
301 /*PRECOMPILE PRECOMPILE PRECOMPILE PRECOMPILE PRECOMPILE PRECOMPILE*/
303 /* #define PRECOMP */
306 #define precompiler "INSERT COMPILER NAME HERE"
307 #define preoptions "INSERT OPTIMISATION OPTIONS HERE"
311 void whetstones(long xtra
, long x100
, int calibrate
);
312 void pa(SPDP e
[4], SPDP t
, SPDP t2
);
313 void po(SPDP e1
[4], long j
, long k
, long l
);
314 void p3(SPDP
*x
, SPDP
*y
, SPDP
*z
, SPDP t
, SPDP t1
, SPDP t2
);
315 void pout(char title
[22], float ops
, int type
, SPDP checknum
,
316 SPDP time
, int calibrate
, int section
);
319 static SPDP loop_time
[9];
320 static SPDP loop_mops
[9];
321 static SPDP loop_mflops
[9];
322 static SPDP TimeUsed
;
324 static char headings
[9][18];
326 static SPDP results
[9];
330 int main(int argc
, char *argv
[])
332 int count
= 10, calibrate
= 1;
342 char compiler
[80] = " ", options
[256] = " ", general
[10][80] = {" "};
345 printf("##########################################\n");
346 printf("%s Precision C/C++ Whetstone Benchmark\n\n", Precision
);
363 printf ("No run time input data\n\n");
366 outfile
= fopen("whets.res","a+");
369 printf ("Cannot open results file \n\n");
370 printf("Press RETURN to exit\n");
376 printf("Calibrate\n");
381 whetstones(xtra
,x100
,calibrate
);
383 printf("%11.2f Seconds %10.0f Passes (x 100)\n", TimeUsed
, (SPDP
)(xtra
));
403 if (TimeUsed
> 0) xtra
= (long)((SPDP
)(duration
* xtra
) / TimeUsed
);
404 if (xtra
< 1) xtra
= 1;
408 printf("\nUse %ld passes (x 100)\n", xtra
);
410 printf("\n %s Precision C/C++ Whetstone Benchmark",Precision
);
413 printf("\n Compiler %s", precompiler
);
414 printf("\n Options %s\n", preoptions
);
419 printf("\nLoop content Result MFLOPS "
420 " MOPS Seconds\n\n");
423 whetstones(xtra
,x100
,calibrate
);
428 mwips
=(float)(xtra
) * (float)(x100
) / (10 * TimeUsed
);
435 printf("%39.3f%19.3f\n\n",mwips
,TimeUsed
);
437 if (Check
== 0) printf("Wrong answer ");
441 /************************************************************************/
442 /* Type details of hardware, software etc. */
443 /************************************************************************/
448 printf ("Enter the following which will be added with results to file WHETS.RES\n");
449 printf ("When submitting a number of results you need only provide details once\n");
450 printf ("but a cross reference such as an abbreviated CPU type would be useful.\n");
451 printf ("You can kill (exit or close) the program now and no data will be added.\n\n");
456 printf ("Computer: ");
459 printf ("CPU chip: ");
462 printf ("Clock MHz: ");
465 printf ("Cache size: ");
468 printf ("H/W options:");
471 printf ("OS version: ");
475 strcpy (compiler
, precompiler
);
476 strcpy (options
, preoptions
);
478 printf ("Compiler: ");
481 printf ("Options: ");
485 printf ("Your name: ");
497 strcpy (compiler
, precompiler
);
498 strcpy (options
, preoptions
);
502 /************************************************************************/
503 /* Add results to output file whets.res */
504 /************************************************************************/
505 fprintf (outfile
, "\n");
506 fprintf (outfile
, "##############################################\n");
507 fprintf (outfile
, "Whetstone %s Precision Benchmark in C/C++\n\n",Precision
);
508 fprintf (outfile
, "Date %s\n", general
[0]);
509 fprintf (outfile
, "Model %s\n", general
[1]);
510 fprintf (outfile
, "CPU %s\n", general
[2]);
511 fprintf (outfile
, "Clock MHz %s\n", general
[3]);
512 fprintf (outfile
, "Cache %s\n", general
[4]);
513 fprintf (outfile
, "H/W options %s\n", general
[5]);
514 fprintf (outfile
, "OS %s\n", general
[6]);
515 fprintf (outfile
, "Compiler %s\n", compiler
);
516 fprintf (outfile
, "Options %s\n", options
);
517 fprintf (outfile
, "Run by %s\n", general
[7]);
518 fprintf (outfile
, "From %s\n", general
[8]);
519 fprintf (outfile
, "Email %s\n", general
[9]);
520 fprintf (outfile
, "\n");
522 fprintf (outfile
,"Loop content Result"
523 " MFLOPS MOPS Seconds\n\n");
525 for (section
=1; section
<9; section
++)
527 fprintf (outfile
, "%s %24.17f ", headings
[section
],
529 if (loop_mops
[section
] == 99999)
531 fprintf (outfile
," %9.3f %9.3f\n",
532 loop_mflops
[section
], loop_time
[section
]);
536 fprintf (outfile
, " %9.3f %9.3f\n",
537 loop_mops
[section
], loop_time
[section
], results
[section
]);
541 fprintf (outfile
, "\nMWIPS ");
542 fprintf (outfile
, "%39.3f%20.3f\n\n",mwips
,TimeUsed
);
543 fprintf (outfile
, "Results to load to spreadsheet ");
544 fprintf (outfile
, " MWIPS Mflops1 Mflops2 Mflops3 Cosmops"
545 " Expmops Fixpmops Ifmops Eqmops\n");
546 fprintf (outfile
, "Results to load to spreadsheet ");
548 fprintf (outfile
, " %9.3f %9.3f %9.3f", mwips
, loop_mflops
[1],
550 fprintf (outfile
, " %9.3f %9.3f %9.3f", loop_mflops
[6],
551 loop_mops
[5], loop_mops
[8]);
552 fprintf (outfile
, " %9.3f %9.3f %9.3f\n\n", loop_mops
[4],
553 loop_mops
[3], loop_mops
[7]);
558 printf ("A new results file will have been created in the same directory as the\n");
559 printf (".EXE files if one did not already exist. If you made a mistake on input, \n");
560 printf ("you can use a text editor to correct it, delete the results or copy \n");
561 printf ("them to a different file name. If you intend to run multiple tests you\n");
562 printf ("you may wish to rename WHETS.RES with a more informative title.\n\n");
563 printf ("Please submit feedback and results files to aburto@nosc.mil or to\n");
564 printf ("Roy_Longbottom@compuserve.com\n\n");
566 #else /* Unixbench */
567 fprintf (stderr
, "COUNT|%.3f|0|MWIPS\n", mwips
);
568 fprintf (stderr
, "TIME|%.3f\n", TimeUsed
);
573 void whetstones(long xtra
, long x100
, int calibrate
)
576 long n1
,n2
,n3
,n4
,n5
,n6
,n7
,n8
,i
,ix
,n1mult
;
579 SPDP e1
[4],timea
,timeb
;
583 SPDP t1
= 0.50000025;
598 /* Section 1, Array elements */
606 for (ix
=0; ix
<xtra
; ix
++)
608 for(i
=0; i
<n1
*n1mult
; i
++)
610 e1
[0] = (e1
[0] + e1
[1] + e1
[2] - e1
[3]) * t
;
611 e1
[1] = (e1
[0] + e1
[1] - e1
[2] + e1
[3]) * t
;
612 e1
[2] = (e1
[0] - e1
[1] + e1
[2] + e1
[3]) * t
;
613 e1
[3] = (-e1
[0] + e1
[1] + e1
[2] + e1
[3]) * t
;
619 timeb
= (dtime()-timea
)/(SPDP
)(n1mult
);
620 pout("N1 floating point\0",(float)(n1
*16)*(float)(xtra
),
621 1,e1
[3],timeb
,calibrate
,1);
623 /* Section 2, Array as parameter */
627 for (ix
=0; ix
<xtra
; ix
++)
637 timeb
= dtime()-timea
;
638 pout("N2 floating point\0",(float)(n2
*96)*(float)(xtra
),
639 1,e1
[3],timeb
,calibrate
,2);
641 /* Section 3, Conditional jumps */
645 for (ix
=0; ix
<xtra
; ix
++)
658 timeb
= dtime()-timea
;
659 pout("N3 if then else \0",(float)(n3
*3)*(float)(xtra
),
660 2,(SPDP
)(j
),timeb
,calibrate
,3);
662 /* Section 4, Integer arithmetic */
668 for (ix
=0; ix
<xtra
; ix
++)
673 k
= l
* k
- (l
-j
) * k
;
680 timeb
= dtime()-timea
;
682 pout("N4 fixed point \0",(float)(n4
*15)*(float)(xtra
),
683 2,x
,timeb
,calibrate
,4);
685 /* Section 5, Trig functions */
690 for (ix
=0; ix
<xtra
; ix
++)
694 x
= t
*atan(t2
*sin(x
)*cos(x
)/(cos(x
+y
)+cos(x
-y
)-1.0));
695 y
= t
*atan(t2
*sin(y
)*cos(y
)/(cos(x
+y
)+cos(x
-y
)-1.0));
701 timeb
= dtime()-timea
;
702 pout("N5 sin,cos etc. \0",(float)(n5
*26)*(float)(xtra
),
703 2,y
,timeb
,calibrate
,5);
705 /* Section 6, Procedure calls */
711 for (ix
=0; ix
<xtra
; ix
++)
715 p3(&x
,&y
,&z
,t
,t1
,t2
);
719 timeb
= dtime()-timea
;
720 pout("N6 floating point\0",(float)(n6
*6)*(float)(xtra
),
721 1,z
,timeb
,calibrate
,6);
723 /* Section 7, Array refrences */
732 for (ix
=0; ix
<xtra
; ix
++)
740 timeb
= dtime()-timea
;
741 pout("N7 assignments \0",(float)(n7
*3)*(float)(xtra
),
742 2,e1
[2],timeb
,calibrate
,7);
744 /* Section 8, Standard functions */
748 for (ix
=0; ix
<xtra
; ix
++)
752 x
= sqrt(exp(log(x
)/t1
));
756 timeb
= dtime()-timea
;
757 pout("N8 exp,sqrt etc. \0",(float)(n8
*4)*(float)(xtra
),
758 2,x
,timeb
,calibrate
,8);
764 void pa(SPDP e
[4], SPDP t
, SPDP t2
)
769 e
[0] = (e
[0]+e
[1]+e
[2]-e
[3])*t
;
770 e
[1] = (e
[0]+e
[1]-e
[2]+e
[3])*t
;
771 e
[2] = (e
[0]-e
[1]+e
[2]+e
[3])*t
;
772 e
[3] = (-e
[0]+e
[1]+e
[2]+e
[3])/t2
;
778 void po(SPDP e1
[4], long j
, long k
, long l
)
786 void p3(SPDP
*x
, SPDP
*y
, SPDP
*z
, SPDP t
, SPDP t1
, SPDP t2
)
797 void pout(char title
[18], float ops
, int type
, SPDP checknum
,
798 SPDP time
, int calibrate
, int section
)
802 Check
= Check
+ checknum
;
803 loop_time
[section
] = time
;
804 strcpy (headings
[section
],title
);
805 TimeUsed
= TimeUsed
+ time
;
809 results
[section
] = checknum
;
813 printf("%s %24.17f ",headings
[section
],results
[section
]);
819 mflops
= ops
/(1000000L*time
);
825 loop_mops
[section
] = 99999;
826 loop_mflops
[section
] = mflops
;
827 printf(" %9.3f %9.3f\n",
828 loop_mflops
[section
], loop_time
[section
]);
834 mops
= ops
/(1000000L*time
);
840 loop_mops
[section
] = mops
;
841 loop_mflops
[section
] = 0;
842 printf(" %9.3f%9.3f\n",
843 loop_mops
[section
], loop_time
[section
]);
851 /*****************************************************/
852 /* Various timer routines. */
853 /* Al Aburto, aburto@nosc.mil, 18 Feb 1997 */
855 /* t = dtime() outputs the current time in seconds. */
856 /* Use CAUTION as some of these routines will mess */
857 /* up when timing across the hour mark!!! */
859 /* For timing I use the 'user' time whenever */
860 /* possible. Using 'user+sys' time is a separate */
864 /* [timer options added here] */
867 /* double starttime,benchtime,dtime(); */
869 /* starttime = dtime(); */
870 /* [routine to time] */
871 /* benchtime = dtime() - starttime; */
874 /* [timer code below added here] */
875 /*****************************************************/
877 /*********************************/
879 /*********************************/
880 /*******************/
882 /*******************/
900 q
= ((SPDP
)(tt
.ticks
+ (tt
.minutes
* 60L * 50L))) / (SPDP
)HZ
;
906 /*****************************************************/
907 /* UNIX dtime(). This is the preferred UNIX timer. */
908 /* Provided by: Markku Kolkka, mk59200@cc.tut.fi */
909 /* HP-UX Addition by: Bo Thide', bt@irfu.se */
910 /*****************************************************/
912 #if !defined(MINIX) || defined(LINUX)
913 #include <sys/time.h>
914 #include <sys/resource.h>
917 #include <sys/syscall.h>
918 #define getrusage(a,b) syscall(SYS_getrusage,a,b)
921 struct rusage rusage
;
927 getrusage(RUSAGE_SELF
,&rusage
);
929 q
= (SPDP
)(rusage
.ru_utime
.tv_sec
);
930 q
= q
+ (SPDP
)(rusage
.ru_utime
.tv_usec
) * 1.0e-06;
936 #include <sys/types.h>
937 #include <sys/times.h>
948 system_hz
= (u32_t
) sysconf(_SC_CLK_TCK
);
949 secs
= tms
.tms_utime
/ system_hz
;
951 tms
.tms_utime
-= secs
* system_hz
;
952 msecs
= tms
.tms_utime
* 100 / system_hz
;
953 q
+= (float) msecs
* 0.01;
959 /***************************************************/
960 /* UNIX_Old dtime(). This is the old UNIX timer. */
961 /* Use only if absolutely necessary as HZ may be */
962 /* ill defined on your system. */
963 /***************************************************/
965 #include <sys/types.h>
966 #include <sys/times.h>
967 #include <sys/param.h>
981 q
= (SPDP
)(tms
.tms_utime
) / (SPDP
)HZ
;
987 /*********************************************************/
988 /* VMS dtime() for VMS systems. */
989 /* Provided by: RAMO@uvphys.phys.UVic.CA */
990 /* Some people have run into problems with this timer. */
991 /*********************************************************/
1002 int proc_system_time
;
1003 int child_user_time
;
1004 int child_system_time
;
1006 struct tbuffer_t tms
;
1014 q
= (SPDP
)(tms
.proc_user_time
) / (SPDP
)HZ
;
1020 /******************************/
1021 /* BORLAND C dtime() for DOS */
1022 /******************************/
1037 q
= 60.0 * (SPDP
)(tnow
.ti_min
);
1038 q
= q
+ (SPDP
)(tnow
.ti_sec
);
1039 q
= q
+ (SPDP
)(tnow
.ti_hund
)/(SPDP
)HZ
;
1045 /***************************************/
1046 /* Microsoft C (MSC) dtime() for DOS */
1047 /* Also suitable for Watcom C/C++ and */
1048 /* some other PC compilers */
1049 /***************************************/
1054 #define HZ CLOCKS_PER_SEC
1062 q
= (SPDP
)tnow
/ (SPDP
)HZ
;
1067 /*************************************/
1068 /* Macintosh (MAC) Think C dtime() */
1069 /*************************************/
1079 q
= (SPDP
)clock() / (SPDP
)HZ
;
1085 /************************************************************/
1086 /* iPSC/860 (IPSC) dtime() for i860. */
1087 /* Provided by: Dan Yergeau, yergeau@gloworm.Stanford.EDU */
1088 /************************************************************/
1090 extern double dclock();
1102 /**************************************************/
1103 /* FORTRAN dtime() for Cray type systems. */
1104 /* This is the preferred timer for Cray systems. */
1105 /**************************************************/
1108 fortran
double second();
1120 /***********************************************************/
1121 /* UNICOS C dtime() for Cray UNICOS systems. Don't use */
1122 /* unless absolutely necessary as returned time includes */
1123 /* 'user+system' time. Provided by: R. Mike Dority, */
1124 /* dority@craysea.cray.com */
1125 /***********************************************************/
1132 clock_t clock(void);
1134 q
= (SPDP
)clock() / (SPDP
)CLOCKS_PER_SEC
;
1140 /********************************************/
1141 /* Another UNIX timer using gettimeofday(). */
1142 /* However, getrusage() is preferred. */
1143 /********************************************/
1145 #include <sys/time.h>
1147 struct timeval tnow
;
1153 gettimeofday(&tnow
,NULL
);
1154 q
= (SPDP
)tnow
.tv_sec
+ (SPDP
)tnow
.tv_usec
* 1.0e-6;
1160 /*****************************************************/
1161 /* Fujitsu UXP/M timer. */
1162 /* Provided by: Mathew Lim, ANUSF, M.Lim@anu.edu.au */
1163 /*****************************************************/
1165 #include <sys/types.h>
1166 #include <sys/timesu.h>
1175 q
= (SPDP
)(rusage
.tms_utime
) * 1.0e-06;
1181 /**********************************************/
1182 /* Macintosh (MAC_TMgr) Think C dtime() */
1183 /* requires Think C Language Extensions or */
1184 /* #include <MacHeaders> in the prefix */
1185 /* provided by Francis H Schiffer 3rd (fhs) */
1186 /* skipschiffer@genie.geis.com */
1187 /**********************************************/
1192 static TMTask mgrTimer
;
1193 static Boolean mgrInited
= false;
1194 static SPDP mgrClock
;
1196 #define RMV_TIMER RmvTime( (QElemPtr)&mgrTimer )
1197 #define MAX_TIME 1800000000L
1198 /* MAX_TIME limits time between calls to */
1199 /* dtime( ) to no more than 30 minutes */
1200 /* this limitation could be removed by */
1201 /* creating a completion routine to sum */
1202 /* 30 minute segments (fhs 1994 feb 9) */
1204 static void Remove_timer( )
1214 mgrClock
+= (MAX_TIME
+ mgrTimer
.tmCount
)*1.0e-6;
1216 if( _atexit( &Remove_timer
) == 0 ) mgrInited
= true;
1220 mgrTimer
.tmAddr
= NULL
;
1221 mgrTimer
.tmCount
= 0;
1222 mgrTimer
.tmWakeUp
= 0;
1223 mgrTimer
.tmReserved
= 0;
1224 InsTime( (QElemPtr
)&mgrTimer
);
1225 PrimeTime( (QElemPtr
)&mgrTimer
, -MAX_TIME
);
1231 /***********************************************************/
1232 /* Parsytec GCel timer. */
1233 /* Provided by: Georg Wambach, gw@informatik.uni-koeln.de */
1234 /***********************************************************/
1236 #include <sys/time.h>
1242 q
= (SPDP
) (TimeNowHigh()) / (SPDP
) CLK_TCK_HIGH
;
1248 /************************************************/
1249 /* Sun Solaris POSIX dtime() routine */
1250 /* Provided by: Case Larsen, CTLarsen.lbl.gov */
1251 /************************************************/
1253 #include <sys/time.h>
1254 #include <sys/resource.h>
1255 #include <sys/rusage.h>
1258 #include <sys/syscall.h>
1261 struct rusage rusage
;
1267 getrusage(RUSAGE_SELF
,&rusage
);
1269 q
= (SPDP
)(rusage
.ru_utime
.tv_sec
);
1270 q
= q
+ (SPDP
)(rusage
.ru_utime
.tv_nsec
) * 1.0e-09;
1277 /****************************************************/
1278 /* Windows NT (32 bit) dtime() routine */
1279 /* Provided by: Piers Haken, piersh@microsoft.com */
1280 /****************************************************/
1282 #include <windows.h>
1288 q
= (SPDP
)GetTickCount() * 1.0e-03;
1294 /*****************************************************/
1295 /* Time according to POSIX.1 - <J.Pelan@qub.ac.uk> */
1296 /* Ref: "POSIX Programmer's Guide" O'Reilly & Assoc.*/
1297 /*****************************************************/
1299 #define _POSIX_SOURCE 1
1302 #include <sys/times.h>
1310 q
= (SPDP
)tms
.tms_utime
/ (SPDP
)CLK_TCK
;