Class XStopWatch

java.lang.Object
org.apache.commons.lang3.time.StopWatch
uk.ac.ebi.utils.time.XStopWatch

public class XStopWatch extends org.apache.commons.lang3.time.StopWatch
A StopWatch with extended functionality.
date
9 Apr 2014
Author:
Marco Brandizi
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static long
    Wrapper of profileNano(Runnable) returning time in ms.
    static long
    Facility to profile (i.e., to time) a task.
    void
    Invokes StopWatch.reset() and then StopWatch.start(), ie, start a new timing session.
    void
    If StopWatch.isSuspended() invokes StopWatch.resume() as usually.
    long
     
    long
    This is similar to profileNano(Runnable), but uses the current watch to time the parameter task.

    Methods inherited from class org.apache.commons.lang3.time.StopWatch

    create, createStarted, formatSplitTime, formatTime, getDuration, getMessage, getNanoTime, getSplitDuration, getSplitNanoTime, getSplitTime, getStartInstant, getStartTime, getStopInstant, getStopTime, getTime, getTime, isStarted, isStopped, isSuspended, reset, resume, split, start, stop, suspend, toSplitString, toString, unsplit

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • XStopWatch

      public XStopWatch()
  • Method Details

    • resumeOrStart

      public void resumeOrStart()
      If StopWatch.isSuspended() invokes StopWatch.resume() as usually. If StopWatch.isStopped() calls StopWatch.start(), if neither is true, it means it's already started and hence does nothing.
    • restart

      public void restart()
      Invokes StopWatch.reset() and then StopWatch.start(), ie, start a new timing session.
    • profileNano

      public static long profileNano(Runnable task)
      Facility to profile (i.e., to time) a task.
      Returns:
      the time elapsed between before and after task.run(). This uses trackNano(Runnable).
    • profile

      public static long profile(Runnable task)
      Wrapper of profileNano(Runnable) returning time in ms.
    • trackNano

      public long trackNano(Runnable task)
      This is similar to profileNano(Runnable), but uses the current watch to time the parameter task. At the end of this method, the current watch will be suspended, every new call to this method will resume the watch and hence the times measured for multiple tasks are added up.
      Returns:
      the time elapsed since the call to this method and the end of the task parameter. Note that timing a task in a multi-thread context might give wrong results, since here we simply measure the time elapsed from start to end, we don't consider the parallelism in between.
    • track

      public long track(Runnable task)
      See Also:
      • wrapper of #trackNano(Runnable), which just converts the result to ms.