net.sf.sparql.benchmarking.parallel
Class ParallelTimer

java.lang.Object
  extended by net.sf.sparql.benchmarking.parallel.ParallelTimer

public class ParallelTimer
extends Object

A Timer that can be used to time runtime where runtime may be being consumed on multiple threads and overlapping, allows you to determine actual runtime used.

Essentially this is just a class that tracks the number of threads that have started the timer and the time at which the timer was last started when there were no active threads using synchronized to ensure that only one thread can access a method at any one time.

Then when the timer is stopped and there are no active threads the total time elapsed can be incremented by the difference between the last start time and the current time. It may be the case that multiple distinct threads have run and started and stopped the timer. But provided active threads is greater than zero at least one thread is performing the operation we wish to time so we are always counting actual time and not counting time multiply as we would be doing if we just summed the individual runtimes of the threads.

Author:
rvesse

Constructor Summary
ParallelTimer()
           
 
Method Summary
 long getActiveThreads()
          Gets the number of active threads currently consuming runtime in parallel
 long getActualRuntime()
          Gets the actual runtime consumed
 void start()
          Starts timing
 void stop()
          Stops timing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParallelTimer

public ParallelTimer()
Method Detail

start

public void start()
Starts timing


stop

public void stop()
Stops timing


getActualRuntime

public long getActualRuntime()
Gets the actual runtime consumed

Returns:
Actual Runtime consumed

getActiveThreads

public long getActiveThreads()
Gets the number of active threads currently consuming runtime in parallel

Returns:
Active Threads


Copyright © 2014. All Rights Reserved.