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