Skip to content
Merged
Show file tree
Hide file tree
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 @@ -25,10 +25,10 @@ public static Benchmark getInstance(){

public void printTimer(int seconds){
TimerTask timerTask = new TimerTask() {
@Override
public void run() { System.out.println(getInstance()); }
@Override
public void run() { System.out.println(benchmarkInstance); }
};
updateTimer = new Timer("Benchmark");
updateTimer = new Timer("Benchmark", true);
updateTimer.scheduleAtFixedRate(timerTask, 0, 1000*seconds);
}

Expand Down Expand Up @@ -62,7 +62,7 @@ public BenchmarkTimer getTimer(String name){
}

public BenchmarkTimer getTotal(String name) {
BenchmarkTimer total = new BenchmarkTimer(name);
BenchmarkTimerTotal total = new BenchmarkTimerTotal(name);
for (BenchmarkTimer b : timerStore.values())
total.add(b);
return total;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@
* @author gavalian
*/
public class BenchmarkTimer {

private String timerName = "generic";
private long totalTime = 0;
private long timeAtResume = 0;
private int numberOfCalls = 0;
private long timeAtResume = 0;
private Boolean isPaused = true;

public BenchmarkTimer(){}

public BenchmarkTimer(String name){

protected int numberOfCalls = 0;
protected long totalTime = 0;

public BenchmarkTimer() {}

public BenchmarkTimer(String name) {
timerName = name;
}

Expand All @@ -38,11 +39,6 @@ public void pause(){
}
}

public void add(BenchmarkTimer b) {
totalTime += b.totalTime;
numberOfCalls += b.numberOfCalls;
}

public void reset(){
totalTime = 0;
timeAtResume = 0;
Expand All @@ -59,12 +55,10 @@ public double getSeconds(){
}

@Override
public String toString(){
StringBuilder str = new StringBuilder();
public String toString() {
double timePerCall = 0.0;
if(numberOfCalls!=0) timePerCall = this.getMiliseconds()/numberOfCalls;
str.append(String.format("TIMER (%-12s) : N Calls %12d, Total Time = %12.2f sec, Unit Time = %12.3f msec",
this.getName(),numberOfCalls,this.getSeconds(),timePerCall));
return str.toString();
if (numberOfCalls != 0) timePerCall = getMiliseconds() / numberOfCalls;
return String.format("TIMER (%-12s) : N Calls %12d, Total Time = %12.2f sec, Unit Time = %12.3f msec",
getName(), numberOfCalls, getSeconds(), timePerCall);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.jlab.utils.benchmark;

import java.util.ArrayList;

/**
*
* @author baltzell
*/
public class BenchmarkTimerTotal extends BenchmarkTimer {

ArrayList<BenchmarkTimer> benchmarks = new ArrayList<>();

public BenchmarkTimerTotal(String name) {
super(name);
}

@Override
public String toString() {
double timePerCall = 0.0;
if (numberOfCalls != 0) timePerCall = getMiliseconds() / numberOfCalls * benchmarks.size();
return String.format("TIMER (%-12s) : N Calls %12d, Total Time = %12.2f sec, Unit Time = %12.3f msec",
getName(), numberOfCalls, getSeconds(), timePerCall);
}

public void add(BenchmarkTimer b) {
benchmarks.add(b);
totalTime += b.totalTime;
numberOfCalls += b.numberOfCalls;
}
}
Loading