1 package org.columba.core.base; 17 18 43 public class StopWatch { 44 private static StopWatch instance = null; 45 46 private long startTime = 0; 47 48 private long stopTime = -1; 49 50 54 public StopWatch() { 55 start(); 56 } 57 58 64 public static StopWatch instance() { 65 if (instance == null) { 66 instance = new StopWatch(); 67 } 68 69 return instance; 70 } 71 72 76 public final void start() { 77 startTime = System.currentTimeMillis(); 78 stopTime = -1; 79 } 80 81 86 public final long stop() { 87 stopTime = System.currentTimeMillis(); 88 89 return (stopTime - startTime); 90 } 91 92 102 public long getTiming() { 103 long time; 104 105 if (stopTime == -1) { 106 time = (System.currentTimeMillis() - startTime); 107 } else { 108 time = (stopTime - startTime); 109 } 110 111 return time; 112 } 113 114 120 @Override 121 public String toString() { 122 return String.valueOf(getTiming()) + " ms"; } 124 } 125 | Popular Tags |