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 * The Hugs 98 system is Copyright (c) Mark P Jones, Alastair Reid, the
28 * Yale Haskell Group, and the Oregon Graduate Institute of Science and
29 * Technology, 1994-1999, All rights reserved. It is distributed as
30 * free software under the license in the file "License", which is
31 * included in the distribution.
33 * $RCSfile: timer.c,v $
35 * $Date: 1999/10/15 21:41:00 $
36 * ------------------------------------------------------------------------*/
39 #if defined(HAVE_SYS_TIME_H) && defined(HAVE_SYS_RESOURCE_H)
41 #include <sys/resource.h>
43 void updateTimers Args((void));
44 long millisecs Args((long));
45 long userElapsed, systElapsed;
48 static long lastUser = 0;
49 static long lastSyst = 0;
52 getrusage(RUSAGE_SELF,&ruse);
54 curr = ruse.ru_utime.tv_sec*1000000L + ruse.ru_utime.tv_usec;
55 userElapsed = curr - lastUser;
58 curr = ruse.ru_stime.tv_sec*1000000L + ruse.ru_stime.tv_usec;
59 systElapsed = curr - lastSyst;
70 void updateTimers Args((void));
71 long millisecs Args((clock_t));
72 clock_t userElapsed=0, systElapsed=0;
75 static clock_t lastUser = 0;
78 userElapsed = curr - lastUser;
84 return (long)((t * 1000)/CLK_TCK);
88 /*-------------------------------------------------------------------------*/