Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*/
public class BenchmarkTimer {

private static final int WARMUP_CALLS = 100;

public static class BenchmarkMultiTimer extends BenchmarkTimer {
ConcurrentHashMap<Integer,Long> timeAtResume = new ConcurrentHashMap<>();
ConcurrentHashMap<Integer,Boolean> isPaused = new ConcurrentHashMap<>();
Expand All @@ -23,8 +25,8 @@ public void resume(int thread) {
}
public void pause(int thread) {
if (!isPaused.get(thread)) {
numberOfCalls.incrementAndGet();
totalTime.addAndGet(System.nanoTime() - timeAtResume.get(thread));
if (numberOfCalls.incrementAndGet() > WARMUP_CALLS)
totalTime.addAndGet(System.nanoTime() - timeAtResume.get(thread));
isPaused.put(thread, true);
}
}
Expand Down Expand Up @@ -62,8 +64,8 @@ public void resume(){

public void pause(){
if(isPaused==false){
totalTime.addAndGet(System.nanoTime() - timeAtResume);
numberOfCalls.incrementAndGet();
if (numberOfCalls.incrementAndGet() > WARMUP_CALLS)
totalTime.addAndGet(System.nanoTime() - timeAtResume);
isPaused = true;
}
}
Expand All @@ -84,13 +86,13 @@ public double getSeconds(){
}

public double getMillisecondsPerCall() {
return numberOfCalls.get() > 0 ? getMilliseconds() / numberOfCalls.get() : 0;
return numberOfCalls.get() > WARMUP_CALLS ? getMilliseconds() / (numberOfCalls.get() - WARMUP_CALLS) : 0;
}

@Override
public String toString() {
return String.format("%-15s : #Calls %12d, Total = %12.2f sec, Unit = %12.3f msec",
getName(), numberOfCalls.get(), getSeconds(), getMillisecondsPerCall());
getName(), numberOfCalls.get()-WARMUP_CALLS, getSeconds(), getMillisecondsPerCall());
}

}
Loading