DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Measuring Program Execution Time with Stopwatch(3C++) - Stopwatch(3C++)

Constructors

Stopwatches have two constructors. The parameterless constructor creates a Stopwatch which is not running and reads zero in each of its displays:

       Stopwatch w;

The copy constructor constructs a Stopwatch which is an exact copy of a second Stopwatch (it has the same status and readings):

        Stopwatch x = w;

Unless they all begin simultaneously (like the runners in a 100-meter dash), it is difficult to keep track of several activities with a single stopwatch. Analogously, it is usually easier to create a different Stopwatch for each independent program activity, and to name each according to the activity it is intended to measure. For example, the following sketch shows three Stopwatches, ostensibly for measuring total execution time, outer loop time, and inner loop time:

       #include <Stopwatch.h>
       main(){
           Stopwatch total;
           Stopwatch outer;
           ...
           for(int i=0;i<N;i++){
               Stopwatch inner;
               for(int j=0;j<M;j++){
                   ...
               }
           }
           ...
       }

As usual, Stopwatches created in inner blocks are local and are destroyed on exit from the block.


Next topic: Stopwatch Status
Previous topic: The Stopwatch Analogy

© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004