StopWatch.java Source code

Java tutorial

Introduction

Here is the source code for StopWatch.java

Source

public class StopWatch {

    public final long t0 = System.currentTimeMillis();

    public final long n0 = System.nanoTime();

    static public StopWatch start() {
        return new StopWatch();
    }

    public long millisEllapsed() {
        return System.currentTimeMillis() - t0;
    }

    public double secondsEllapsed() {
        return millisEllapsed() / 1000.0;
    }

    public long nanoEllapsed() {
        return System.nanoTime() - n0;
    }

}