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

Alachisoft.NCache.Common.StopWatch Maven / Gradle / Ivy

There is a newer version: 5.3.3
Show newest version
package Alachisoft.NCache.Common;

public class StopWatch {

    private long startTime = 0;
    private long stopTime = 0;
    private boolean running = false;


    public void start() {
        this.startTime = System.nanoTime();
        this.running = true;
    }


    public void stop() {
        this.stopTime = System.nanoTime();
        this.running = false;
    }

    public void restart()
    {
        stop();
        start();
    }


    //elaspsed time in milliseconds
    public long getElapsedTime() {
        long elapsed;
        if (running) {
            elapsed = (System.nanoTime() - startTime);
        } else {
            elapsed = (stopTime - startTime);
        }
        return elapsed/1000;
    }


    //elaspsed time in seconds
    public long getElapsedTimeSecs() {
        long elapsed;
        if (running) {
            elapsed = ((System.nanoTime() - startTime));
        } else {
            elapsed = ((stopTime - startTime));
        }
        return elapsed/1000;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy