public class timertest { public static void main(String[]args) { TickCounter tc = new TickCounter(); Timer tm = new Timer(); System.out.println("Testing high-performance timers..."); long elap = 0; for (int i=0;i<10;i++) { long start = System.currentTimeMillis(); tc.start(); tm.start(); try { Thread.sleep(500); } catch (Throwable exn) {} tc.stop(); tm.stop(); elap += System.currentTimeMillis() - start; try { Thread.sleep(100); } catch (Throwable exn) {} } double reftime = elap * 1000.0; double tmtime = tm.micros(); double tctime = tc.ticksToMicros(tc.elapsed); if (Math.abs(reftime - tmtime) > 0.1 * tmtime || Math.abs(reftime - tmtime) > 0.1 * tctime) System.out.println("FAILED - reftime: "+reftime+"us\n"+ " TickCounter time: "+tctime+"us\n"+ " Timer time: "+tmtime+"us"); else System.out.println("PASSED"); tm.reset(); tc.reset(); if (tm.micros() != 0.0) System.out.println("Timer.reset() failed!!!"); if (tc.elapsed != 0) System.out.println("TickCounter.reset() failed!!!"); double gran = tc.granularity(); double over = tc.overhead(); if (gran == 0.0 || over == 0.0 || gran < 0.5 * over) System.out.println("inconsistent TickCounter overhead: "+over+" granularity:"+gran); System.out.println("done."); }}