The Support Kit: BStopWatch

Derived from: public BObject

Declared in: <support/StopWatch.h>


Overview

The BStopWatch class is a debugging tool that you can use to time the execution of portions of your code. The class has no member functions or (public) member data. When a BStopWatch object is constructed, it starts its internal timer. When it's deleted it stops the timer and prints the elapsed time to standard out in this format:

StopWatch "name": f usecs.

Where name is the name that you gave to the object when you constructed it, and f is the elapsed time in microseconds reckoned to one decimal place.

For example ...

   #include <StopWatch.h>
   ...
   BStopWatch *myWatch = new BStopWatch("Timer 0");
   /* The code you want to time goes here. */
   delete myWatch;
   ...

... would produce, on standard out, a message that goes something like this:

   StopWatch "Timer 0": 492416.3 usecs.

This would indicate that the timed code took about half a second to execute --remember, you're looking at microseconds.

BStopWatch objects are handy little critters. They're particularly useful if you want to get a general idea of where your cycles are going. But you shouldn't rely on them for painfully accurate measurements.

Important: Unlike the other debugging tools defined by the Support Kit, there's no run- time toggle to control a BStopWatch. Make sure you remove your BStopWatch objects after you're done debugging your code.


Constructor and Destructor


BStopWatch()

      BStopWatch(const char *name)

Creates a BStopWatch object, names it name, and starts its internal timer.


~BStopWatch()

      virtual ~BStopWatch(void)

Stops the object's timer, spits out a timing message to standard out, and then destroys the object and everything it believes in.




The Be Book, HTML Edition, for Developer Release 8 of the Be Operating System.

Copyright © 1996 Be, Inc. All rights reserved.

Be, the Be logo, BeBox, BeOS, BeWare, and GeekPort are trademarks of Be, Inc.

Last modified September 6, 1996.