home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 May / PCP163A.iso / handson / files / copyjava.exe / stage4 / 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 = 0L;
  3.    static long stopTime = 0L;
  4.    static long sampTimeTot = 0L;
  5.    static int sampTimeCount = 0;
  6.    static long timeTot = 0L;
  7.    static int count = 0;
  8.  
  9.    public static void report() {
  10.       System.out.println("Sample");
  11.       System.out.println("\t# of calls: " + sampTimeCount);
  12.       System.out.println("\ttotal time: " + sampTimeTot);
  13.       System.out.println("\tper pass: " + (double)sampTimeTot / (double)sampTimeCount);
  14.    }
  15.  
  16.    public static void sampleEnd() {
  17.       sampTimeTot = timeTot;
  18.       sampTimeCount = count;
  19.       timeTot = 0L;
  20.       count = 0;
  21.  
  22.       for(int var0 = 0; var0 < sampTimeCount; ++var0) {
  23.          start();
  24.          stop();
  25.       }
  26.  
  27.       sampTimeTot -= timeTot;
  28.       timeTot = 0L;
  29.       count = 0;
  30.    }
  31.  
  32.    public static void sampleStart() {
  33.       timeTot = 0L;
  34.       count = 0;
  35.    }
  36.  
  37.    public static void start() {
  38.       startTime = System.currentTimeMillis();
  39.    }
  40.  
  41.    public static void stop() {
  42.       stopTime = System.currentTimeMillis();
  43.       timeTot += stopTime - startTime;
  44.       ++count;
  45.    }
  46. }
  47.