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 @@ -7,7 +7,6 @@
import java.util.Timer;
import java.util.TimerTask;
import org.jlab.utils.benchmark.BenchmarkTimer.BenchmarkMultiTimer;
import org.jlab.utils.benchmark.BenchmarkTimer.BenchmarkTimerTotal;

/**
*
Expand Down Expand Up @@ -74,13 +73,6 @@ public BenchmarkTimer getTimer(String name){
return timerStore.getOrDefault(name, null);
}

public BenchmarkTimer getTotal(String name) {
BenchmarkTimerTotal total = new BenchmarkTimerTotal(name);
for (BenchmarkTimer b : timerStore.values())
total.add(b);
return total;
}

@Override
public String toString(){
StringBuilder s = new StringBuilder();
Expand All @@ -100,15 +92,20 @@ public String toString(){
s.append(b);
s.append(" *\n");
}
s.append("* ");
s.append(getTotal(""));
s.append(" *\n");
s.append(margins);
s.append("\n");
}
return s.toString();
}

public String[] toCSV() {
return new String[]{
String.join(",",timerStore.keySet()) + ",TOTAL",
String.join(",",timerStore.values().stream().map(x -> String.valueOf(x.getMillisecondsPerCall())).toList())
+ "," + timerStore.values().stream().mapToDouble(x -> x.getMillisecondsPerCall()).sum()
};
}

public static void main(String[] args){
Benchmark b = getInstance();
b.printTimer(10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,6 @@ public void reset(){
}
}

public static class BenchmarkTimerTotal extends BenchmarkMultiTimer {
ArrayList<BenchmarkTimer> benchmarks = new ArrayList<>();
public BenchmarkTimerTotal(String name) { super(name); }
public void add(BenchmarkTimer b) {
benchmarks.add(b);
totalTime.addAndGet(b.totalTime.get());
numberOfCalls.addAndGet(b.numberOfCalls.get());
}
}

private String timerName = "generic";
private long timeAtResume = 0;
private Boolean isPaused = true;
Expand Down Expand Up @@ -96,10 +86,10 @@ public double getSeconds(){
@Override
public String toString() {
return String.format("%-15s : #Calls %12d, Total = %12.2f sec, Unit = %12.3f msec",
getName(), numberOfCalls.get(), getSeconds(), getTimePerCall());
getName(), numberOfCalls.get(), getSeconds(), getMillisecondsPerCall());
}

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