home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 May / PCP163A.iso / handson / files / java / stage3 / Timer.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-01-30  |  1.4 KB  |  47 lines

  1. public class Timer {
  2.    static long startTime;
  3.    static long stopTime;
  4.    static long sampTimeTot;
  5.    static int sampTimeCount;
  6.    static long timeTot;
  7.    static int count;
  8.  
  9.    public static void start() {
  10.       startTime = System.currentTimeMillis();
  11.    }
  12.  
  13.    public static void stop() {
  14.       stopTime = System.currentTimeMillis();
  15.       timeTot += stopTime - startTime;
  16.       ++count;
  17.    }
  18.  
  19.    public static void sampleEnd() {
  20.       sampTimeTot = timeTot;
  21.       sampTimeCount = count;
  22.       timeTot = 0L;
  23.       count = 0;
  24.  
  25.       for(int var0 = 0; var0 < sampTimeCount; ++var0) {
  26.          start();
  27.          stop();
  28.       }
  29.  
  30.       sampTimeTot -= timeTot;
  31.       timeTot = 0L;
  32.       count = 0;
  33.    }
  34.  
  35.    public static void sampleStart() {
  36.       timeTot = 0L;
  37.       count = 0;
  38.    }
  39.  
  40.    public static void report() {
  41.       System.out.println("Sample");
  42.       System.out.println("\t# of calls: " + sampTimeCount);
  43.       System.out.println("\ttotal time: " + sampTimeTot);
  44.       System.out.println("\tper pass: " + (double)sampTimeTot / (double)sampTimeCount);
  45.    }
  46. }
  47.