1 /* -*- mode: hugs-c; -*- */
2 /* --------------------------------------------------------------------------
3 * This file provides a simple mechanism for measuring elapsed time on Unix
4 * machines (more precisely, on any machine with an rusage() function).
5 * A somewhat limited version for other systems is also included, believed
6 * to be ANSI compatible, but not guaranteed ...
8 * It is included in the Hugs distribution for the purpose of benchmarking
9 * the Hugs interpreter, comparing its performance across a variety of
10 * different machines, and with other systems for similar languages.
12 * To make use of these functions, use the --enable-timer when configuring
13 * Hugs or change the setting of "WANT_TIMER" in config.h and recompile
16 * It would be somewhat foolish to try to use the timings produced in this
17 * way for anything other than the purpose described above. In particular,
18 * using timings to compare the performance of different versions of an
19 * algorithm is likely to give very misleading results. The current
20 * implementation of Hugs as an interpreter, without any significant
21 * optimizations, means that there are much more significant overheads than
22 * can be accounted for by small variations in Hugs code.
24 * Copyright (c) The University of Nottingham and Yale University, 1994-1997.
25 * All rights reserved. See NOTICE for details and conditions of use etc...
26 * Hugs version 1.4, December 1997
28 * $RCSfile: timer.c,v $
30 * $Date: 1998/12/02 13:22:46 $
31 * ------------------------------------------------------------------------*/
34 #if defined(HAVE_SYS_TIME_H) && defined(HAVE_SYS_RESOURCE_H)
36 #include <sys/resource.h>
38 void updateTimers Args((void));
39 long millisecs Args((long));
40 long userElapsed, systElapsed;
43 static long lastUser = 0;
44 static long lastSyst = 0;
47 getrusage(RUSAGE_SELF,&ruse);
49 curr = ruse.ru_utime.tv_sec*1000000L + ruse.ru_utime.tv_usec;
50 userElapsed = curr - lastUser;
53 curr = ruse.ru_stime.tv_sec*1000000L + ruse.ru_stime.tv_usec;
54 systElapsed = curr - lastSyst;
65 void updateTimers Args((void));
66 long millisecs Args((clock_t));
67 clock_t userElapsed=0, systElapsed=0;
70 static clock_t lastUser = 0;
73 userElapsed = curr - lastUser;
79 return (long)((t * 1000)/CLK_TCK);
83 /*-------------------------------------------------------------------------*/