1 // BEGIN_COPYRIGHT -*- glean -*-
3 // Copyright (C) 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 // tbasicperf.cpp: implementation of example class for basic
32 // To customize this for benchmarking a particular function,
33 // create a new performance test object of type GLEAN::Perf,
34 // overriding the preop(), op(), and postop() methods as needed.
35 // (For OpenGL timing tests preop() and postop() will both call
36 // glFinish(), but other pre- and post-ops may be used for
37 // timing things other than OpenGL.) Then invoke the object's
38 // calibrate() and time() methods as shown in runOne().
40 #include "tbasicperf.h"
45 class MyPerf
: public GLEAN::Timer
{
49 void preop() { glFinish(); }
52 Sleep(msec
); /* milliseconds */
54 usleep(msec
*1000); /* microseconds */
57 void postop() { glFinish(); }
59 MyPerf() { msec
= 100; }
63 // Complex results helper functions
66 diffHeader(bool& same
, const string
& name
,
67 GLEAN::DrawingSurfaceConfig
* config
, GLEAN::Environment
* env
) {
70 env
->log
<< name
<< ": DIFF "
71 << config
->conciseDescription() << '\n';
79 ///////////////////////////////////////////////////////////////////////////////
80 // runOne: Run a single test case
81 ///////////////////////////////////////////////////////////////////////////////
83 BasicPerfTest::runOne(BasicPerfResult
& r
, Window
&w
) {
88 for (int i
= 0; i
< 5; i
++) {
90 double t
= perf
.time();
91 w
.swap(); // So user can see something
94 sort(m
.begin(), m
.end());
95 r
.timeAvg
= (m
[1] + m
[2] + m
[3]) / 3.0;
99 } // BasicPerfTest::runOne
101 ///////////////////////////////////////////////////////////////////////////////
102 // logOne: Log a single test case
103 ///////////////////////////////////////////////////////////////////////////////
105 BasicPerfTest::logOne(BasicPerfResult
& r
) {
109 } // BasicPerfTest::logOne
111 ///////////////////////////////////////////////////////////////////////////////
112 // compareOne: Compare results for a single test case
113 ///////////////////////////////////////////////////////////////////////////////
115 BasicPerfTest::compareOne(BasicPerfResult
& oldR
, BasicPerfResult
& newR
) {
117 const char *title
= "100mS sleep";
119 if (newR
.timeLow
< oldR
.timeLow
) {
120 double percent
= (100.0
121 * (oldR
.timeLow
- newR
.timeLow
)
122 / newR
.timeLow
+ 0.5);
123 if (percent
>= 5.0) {
124 diffHeader(same
, name
, oldR
.config
, env
);
126 << env
->options
.db1Name
134 if (newR
.timeHigh
> oldR
.timeHigh
) {
135 double percent
= (100.0
136 * (newR
.timeHigh
- oldR
.timeHigh
)
137 / oldR
.timeHigh
+ 0.5);
138 if (percent
>= 5.0) {
139 diffHeader(same
, name
, oldR
.config
, env
);
141 << env
->options
.db2Name
150 if (same
&& env
->options
.verbosity
) {
153 << newR
.config
->conciseDescription()
155 << env
->options
.db2Name
156 << " test time falls within the"
157 << " valid measurement range of\n\t"
158 << env
->options
.db1Name
161 if (env
->options
.verbosity
) {
162 env
->log
<< env
->options
.db1Name
<< ':';
164 env
->log
<< env
->options
.db2Name
<< ':';
167 } // BasicPerfTest::compareOne
170 BasicPerfTest::logStats(BasicPerfResult
& r
) {
171 env
->log
<< "\tAverage = "
180 ///////////////////////////////////////////////////////////////////////////////
181 // The test object itself:
182 ///////////////////////////////////////////////////////////////////////////////
183 BasicPerfTest
basicPerfTest("basicPerf", "window",
184 "This trivial test simply verifies the internal support for basic\n"
185 "performance tests. It is run on every OpenGL-capable drawing surface\n"
186 "configuration that supports creation of a window. If everything is\n"
187 "working correctly, each result should be close to 0.1 second.\n");