Alachisoft.NCache.Common.StopWatch Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nc-common Show documentation
Show all versions of nc-common Show documentation
Internal package of Alachisoft.
package Alachisoft.NCache.Common;
public class StopWatch {
private long startTime = 0;
private long stopTime = 0;
private boolean running = false;
public void start() {
this.startTime = System.nanoTime();
this.running = true;
}
public void stop() {
this.stopTime = System.nanoTime();
this.running = false;
}
public void restart()
{
stop();
start();
}
//elaspsed time in milliseconds
public long getElapsedTime() {
long elapsed;
if (running) {
elapsed = (System.nanoTime() - startTime);
} else {
elapsed = (stopTime - startTime);
}
return elapsed/1000;
}
//elaspsed time in seconds
public long getElapsedTimeSecs() {
long elapsed;
if (running) {
elapsed = ((System.nanoTime() - startTime));
} else {
elapsed = ((stopTime - startTime));
}
return elapsed/1000;
}
}