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

io.deephaven.benchmark.util.Timer Maven / Gradle / Ivy

The newest version!
/* Copyright (c) 2022-2023 Deephaven Data Labs and Patent Pending */
package io.deephaven.benchmark.util;

import java.time.Duration;
import java.time.temporal.ChronoUnit;

/**
 * Timer used to get the duration of a block of code. Precision is in milliseconds.
 */
public class Timer {
    /**
     * Get the elapsed time since epoch in milliseconds
     * 
     * @return current time epoch
     */
    static public long now() {
        return System.currentTimeMillis();
    }

    /**
     * Start the timer
     * 
     * @return a Timer instance initialized to the current time
     */
    static public Timer start() {
        return new Timer();
    }

    /**
     * The time the Timer was initialized
     */
    final public long beginTime = now();

    protected Timer() {}

    /**
     * The elapsed time in milliseconds between now and the beginning when this Timer was initialized
     * 
     * @return time elapsed since start
     */
    public Duration duration() {
        return Duration.of(now() - beginTime, ChronoUnit.MILLIS);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy