Skip to content

Instantly share code, notes, and snippets.

@Yuiki Yuiki/Timer.java
Created Feb 4, 2017

Embed
What would you like to do?
class Timer {
private long startNanoTime, endNanoTime = 0L;
void start() {
this.startNanoTime = System.nanoTime();
}
void stop() {
if (startNanoTime != 0L) {
this.endNanoTime = System.nanoTime();
} else {
throw new IllegalStateException();
}
}
String getResultTimeInMilliseconds() {
long resultTime = (endNanoTime - startNanoTime) / 1000000;
startNanoTime = 0L;
endNanoTime = 0L;
return "計測時間:" + resultTime + "ms";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.