Tools.h++ Manual
104011 Tandem Computers Incorporated 21-9
21
RWBench
Synopsis
#include <rw/bench.h>
(Abstract base class)
Description This is an abstract class that can automate the process of benchmarking a piece
of code. To use it, derive a class from
RWBench
, including a deļ¬nition for the
virtual function
doLoop(unsigned long N)
. This function should perform
N operations of the type that you are trying to benchmark.
RWBench
will call
doLoop()
over and over again until a preset amount of time has elapsed. It
will then sum the total number of operations performed.
To run, construct an instance of your derived class and then call
go()
. Then
call
report()
to get a standard summary. For many compilers, this summary
will automatically include the compiler type and memory model. You can call
ops()
,
outerLoops()
, etc. for more detail.
If you wish to correct for overhead, then provide an
idleLoop()
function
which should do non-benchmark related calculations.
Example This example benchmarks the time required to return a hash value for a
Tools.h++ string versus a Borland string.
Code Example 21-1 (1 of 3)
#include <rw/bench.h> /* Benchmark software */
#include <rw/cstring.h >/* Tools.h++ string class */
#include <strng.h> /* Borland string class */
#include <stdlib.h>
// The string to be hashed:
const char* cs = "A 22 character string.";
class TestBCCString : public RWBench {
public:
TestBCCString() { }
virtual void doLoop(unsigned long n);
virtual void idleLoop(unsigned long n);
virtual void what(ostream& s) const
{ s << "Borland hashing string \"" << cs << "\"\n"; }
};
class TestRWCString : public RWBench {
public: