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

netflix.ocelli.functions.Stopwatches Maven / Gradle / Ivy

There is a newer version: 0.1.0-rc.2
Show newest version
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);
                    }
                };
            }
        };
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy