All Downloads are FREE. Search and download functionalities are using the official Maven repository.

netflix.ocelli.util.Stopwatch Maven / Gradle / Ivy

There is a newer version: 0.1.0-rc.2
Show newest version
package netflix.ocelli.util;

import java.util.concurrent.TimeUnit;

public class Stopwatch {

    public static Stopwatch createStarted() {
        return new Stopwatch(System.nanoTime());
    }
    
    private Stopwatch(long startTime) {
        this.startTime = startTime;
    }
    
    private long startTime;
    private long endTime = -1;
    
    public long elapsed(TimeUnit units) {
        return units.convert(getRawElapsed(), TimeUnit.NANOSECONDS);
    }
    
    public long getRawElapsed() {
        if (endTime == -1) {
            return System.nanoTime() - startTime;
        }
        return endTime - startTime;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy