netflix.ocelli.functions.Stopwatches Maven / Gradle / Ivy
package netflix.ocelli.functions;
import java.util.concurrent.TimeUnit;
import netflix.ocelli.util.Stopwatch;
import rx.functions.Func0;
/**
* Utility class to create common Stopwatch factories in the form of Func0
* functions
*
* @author elandau
*
*/
public class Stopwatches {
/**
* Stopwatch that calls System.nanoTime()
*
* @return
*/
public static Func0 systemNano() {
return new Func0() {
@Override
public Stopwatch call() {
return new Stopwatch() {
private final long startTime = System.nanoTime();
@Override
public long elapsed(TimeUnit units) {
return units.convert(System.nanoTime() - startTime, TimeUnit.NANOSECONDS);
}
};
}
};
}
}