/** * Return an new timer object with the default clock implementation. * * @return a new timer */ public static Timer of() { return new Timer(System::nanoTime); }
/** * Return an new timer object which uses the given clock for measuring the * execution time. * * @param clock the clock used for measuring the execution time * @return a new timer */ public static Timer of(final Clock clock) { requireNonNull(clock); return clock instanceof NanoClock ? new Timer(System::nanoTime) : new Timer(() -> nanos(clock)); }