Improve Time Profiler
This commit is contained in:
@@ -1,16 +1,14 @@
|
|||||||
package com.bartlomiejpluta.base.util.profiler;
|
package com.bartlomiejpluta.base.util.profiler;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public class TimeProfiler {
|
public class TimeProfiler {
|
||||||
private static final Logger log = LoggerFactory.getLogger(TimeProfiler.class);
|
|
||||||
|
|
||||||
private static final DecimalFormat DF = new DecimalFormat("0.00");
|
private static final DecimalFormat DF = new DecimalFormat("0.00");
|
||||||
private final Map<String, Double> averages = new HashMap<>();
|
private final Map<String, Double> averages = new HashMap<>();
|
||||||
|
|
||||||
@@ -26,10 +24,10 @@ public class TimeProfiler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void printResult() {
|
public void logResult() {
|
||||||
averages.entrySet().stream()
|
averages.entrySet().stream()
|
||||||
.sorted(Entry.<String, Double>comparingByValue().reversed())
|
.sorted(Entry.<String, Double>comparingByValue().reversed())
|
||||||
.forEachOrdered(entry -> log.info("[{}]: [{}sms] [{}sus] [{}ns]",
|
.forEachOrdered(entry -> log.info("[{}]: [{}ms] [{}us] [{}ns]",
|
||||||
entry.getKey(),
|
entry.getKey(),
|
||||||
DF.format(entry.getValue() / 1_000_000),
|
DF.format(entry.getValue() / 1_000_000),
|
||||||
DF.format(entry.getValue() / 1_000),
|
DF.format(entry.getValue() / 1_000),
|
||||||
|
|||||||
Reference in New Issue
Block a user