1 // BEGIN_COPYRIGHT -*- glean -*-
3 // Copyright (C) 1999-2000 Allen Akin All Rights Reserved.
5 // Permission is hereby granted, free of charge, to any person
6 // obtaining a copy of this software and associated documentation
7 // files (the "Software"), to deal in the Software without
8 // restriction, including without limitation the rights to use,
9 // copy, modify, merge, publish, distribute, sublicense, and/or
10 // sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
19 // KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
20 // WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
21 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ALLEN AKIN BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 // AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
24 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 // DEALINGS IN THE SOFTWARE.
29 // timer.h: Simple benchmark timing utilities based on the previous timer.h
30 // Modified from timer.h by Rickard E. (Rik) Faith <faith@valinux.com>
32 // Timer objects provide a framework for measuring the rate at which an
33 // operation can be performed.
41 double overhead
; // Overhead (in seconds) of initial op,
42 // final op, and timer access.
44 int calibrated
; // Has calibrate been called?
46 double chooseRunTime(); // Select a runtime that will reduce random
47 // timing error to an acceptable level.
50 virtual void premeasure() {}; // called in measure(), before time()
51 virtual void postmeasure() {}; // called in measure(), after time()
52 virtual void preop() {}; // before op, in each loop in time()
53 virtual void op() {}; // in each loop in time()
54 virtual void postop() {}; // after op, in each loop in time()
55 virtual double compute(double t
) {
56 // modify measure()'s result -- e.g., by computing a rate
62 double getClock(); // Get wall-clock time, in seconds
63 double waitForTick(); // Wait for next clock tick; return time
64 void measure(int count
,
65 double* low
, double* avg
, double* high
);
67 Timer() { overhead
= 0.0; calibrated
= false; }
68 virtual ~Timer() { /* just silence warning */ }