1 19 package org.netbeans.modules.java.source.engine; 20 21 27 public class ElapsedTimer { 28 private long startTime; 30 private long stopTime; 31 32 35 public ElapsedTimer() { 36 reset(); 37 } 38 39 42 public void stop() { 43 stopTime = System.currentTimeMillis(); 44 } 45 46 49 public final void reset() { 50 startTime = System.currentTimeMillis(); 51 } 52 53 public long getElapsedMilliseconds() { 54 long st = (stopTime == 0) ? System.currentTimeMillis() : stopTime; 55 return st - startTime; 56 } 57 58 public int getElapsedSeconds() { 59 return (int)(getElapsedMilliseconds() / 1000L); 60 } 61 62 public String toString() { 63 long ms = getElapsedMilliseconds(); 64 StringBuffer sb = new StringBuffer (); 65 sb.append(ms / 1000L); 66 sb.append('.'); 67 sb.append(ms % 1000L); 68 sb.append(" seconds"); 69 return sb.toString(); 70 } 71 } 72 73 74 75 | Popular Tags |