1 <<<<<<<<<<<<<< variant A
3 >>>>>>>>>>>>>> variant B
4 ======= end of combination
5 /* --------------------------------------------------------------------------
6 * This file provides a simple mechanism for measuring elapsed time on Unix
7 * machines (more precisely, on any machine with an rusage() function).
8 * A somewhat limited version for other systems is also included, believed
9 * to be ANSI compatible, but not guaranteed ...
11 * It is included in the Hugs distribution for the purpose of benchmarking
12 * the Hugs interpreter, comparing its performance across a variety of
13 * different machines, and with other systems for similar languages.
15 * To make use of these functions, use the --enable-timer when configuring
16 * Hugs or change the setting of "WANT_TIMER" in config.h and recompile
19 * It would be somewhat foolish to try to use the timings produced in this
20 * way for anything other than the purpose described above. In particular,
21 * using timings to compare the performance of different versions of an
22 * algorithm is likely to give very misleading results. The current
23 * implementation of Hugs as an interpreter, without any significant
24 * optimizations, means that there are much more significant overheads than
25 * can be accounted for by small variations in Hugs code.
27 * Hugs 98 is Copyright (c) Mark P Jones, Alastair Reid and the Yale
28 * Haskell Group 1994-99, and is distributed as Open Source software
29 * under the Artistic License; see the file "Artistic" that is included
30 * in the distribution for details.
32 * $RCSfile: timer.c,v $
34 * $Date: 1999/02/03 17:08:43 $
35 * ------------------------------------------------------------------------*/
38 #if defined(HAVE_SYS_TIME_H) && defined(HAVE_SYS_RESOURCE_H)
40 #include <sys/resource.h>
42 void updateTimers Args((void));
43 long millisecs Args((long));
44 long userElapsed, systElapsed;
47 static long lastUser = 0;
48 static long lastSyst = 0;
51 getrusage(RUSAGE_SELF,&ruse);
53 curr = ruse.ru_utime.tv_sec*1000000L + ruse.ru_utime.tv_usec;
54 userElapsed = curr - lastUser;
57 curr = ruse.ru_stime.tv_sec*1000000L + ruse.ru_stime.tv_usec;
58 systElapsed = curr - lastSyst;
69 void updateTimers Args((void));
70 long millisecs Args((clock_t));
71 clock_t userElapsed=0, systElapsed=0;
74 static clock_t lastUser = 0;
77 userElapsed = curr - lastUser;
83 return (long)((t * 1000)/CLK_TCK);
87 /*-------------------------------------------------------------------------*/