/** * @return the time elapsed (in milliseconds) since the last time this timer was started. If the timer is not running now 0 is returned. */ public long getElapsed() { return isStarted() ? System.currentTimeMillis() - _startTime : 0; }
/** * @return the time elapsed (in milliseconds) since the last time this timer was started. If the timer is not running now 0 is returned. */ public long getElapsed() { return isStarted() ? System.currentTimeMillis() - _startTime : 0; }
/** * Stop the timer, increment the _count and update the total time spent. If timer has been started multiple times this function will only decrement the * internal counter. Time information is updated only when all starts are evened out by stops. * * @return Return the total time spent after last start(), -1 if timer is still running, -Long.MAX_VALUE on error */ public long stop() { if (!isStarted()) { _logger.fine(() -> String.format("Ignoring attempt to stop a timer (\"%s\") that is not running. Timer results are incorrect for multi-threaded code.", _name)); return -Long.MAX_VALUE; } // Decrement start counter. _startCount--; if (!isStarted()) { _lastTime = System.currentTimeMillis() - _startTime; _totalTime += _lastTime; _startTime = NOT_STARTED; _count++; return _lastTime; } return -1; }
/** * Stop the timer, increment the _count and update the total time spent. If timer has been started multiple times this function will only decrement the * internal counter. Time information is updated only when all starts are evened out by stops. * * @return Return the total time spent after last start(), -1 if timer is still running, -Long.MAX_VALUE on error */ public long stop() { if (!isStarted()) { _logger.fine(() -> String.format("Ignoring attempt to stop a timer (\"%s\") that is not running. Timer results are incorrect for multi-threaded code.", _name)); return -Long.MAX_VALUE; } // Decrement start counter. _startCount--; if (!isStarted()) { _lastTime = System.currentTimeMillis() - _startTime; _totalTime += _lastTime; _startTime = NOT_STARTED; _count++; return _lastTime; } return -1; }
/** * If started _stop the timer and then start it again. */ public void restart() { if (isStarted()) stop(); start(); }
/** * If started _stop the timer and then start it again. */ public void restart() { if (isStarted()) stop(); start(); }
row.add(nf.format(timer.getAverage())); if (timer.isStarted()) row.add(String.valueOf(timer.getElapsed())); else
row.add(nf.format(timer.getAverage())); if (timer.isStarted()) row.add(String.valueOf(timer.getElapsed())); else
if (!timer.isStarted()) System.out.println(timer.getName() + ": " + timer.getTotal() + "ms");
if (!timer.isStarted()) System.out.println(timer.getName() + ": " + timer.getTotal() + "ms");