1 package net
.sourceforge
.aprog
.tools
;
3 import static java
.lang
.System
.currentTimeMillis
;
6 * Simple time measuring class to manually instrument blocks of code.
7 * <br>Call {@link #tic()} at the beginning and {@link #toc()} at the end.
8 * <br>{@link #getTotalTime()} gives the total time (cumulative) spent in {@link #tic()} {@link #toc()} intervals.
10 * @author codistmonk (creation 2013-01-25)
12 public final class TicToc
{
14 private long totalTime
;
16 private long ticTocTime
;
21 * Starts a time interval.
23 * @return The current time in milliseconds
25 public final long tic() {
26 this.totalTime
+= this.ticTocTime
;
28 return this.t0
= currentTimeMillis();
32 * @return The time in milliseconds since the last call to {@link #tic()}
34 public final long toc() {
35 this.ticTocTime
= currentTimeMillis() - this.t0
;
37 return this.ticTocTime
;
41 * @return The cumulative time of this timer (sum of tic toc intervals)
43 public final long getTotalTime() {
44 return this.totalTime
+ this.ticTocTime
;