Skip to content

Instantly share code, notes, and snippets.

@Yuiki
Created February 4, 2017 02:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yuiki/b779fe62c54cbd5e540eec543ce84d7d to your computer and use it in GitHub Desktop.
Save Yuiki/b779fe62c54cbd5e540eec543ce84d7d to your computer and use it in GitHub Desktop.
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