took invocations counting out of lambda

This commit is contained in:
Sander Hautvast 2018-03-29 14:22:21 +02:00
parent a00c2e10a4
commit e50989fb37

View file

@ -25,20 +25,19 @@ public class Registry {
private static SortedMap<Long, Report> sortedMethodsByDuration() { private static SortedMap<Long, Report> sortedMethodsByDuration() {
SortedMap<Long, Report> sortedByTotal = new ConcurrentSkipListMap<>(Comparator.reverseOrder()); SortedMap<Long, Report> sortedByTotal = new ConcurrentSkipListMap<>(Comparator.reverseOrder());
methods.forEach((name, results) -> { methods.forEach((name, measurements) -> {
LongAdder adder = new LongAdder(); long totalDuration = measurements.stream().mapToLong(Method::getDuration).sum();
long totalDuration = results.stream().peek((r) -> adder.increment()).mapToLong(r -> r.getDuration()).sum(); sortedByTotal.put(totalDuration, new Report(name, measurements.size(), totalDuration));
sortedByTotal.put(totalDuration, new Report(name, adder.longValue(), totalDuration));
}); });
return sortedByTotal; return sortedByTotal;
} }
static class Report { static class Report {
final String name; final String name;
final long invocations; final int invocations;
final long totalDuration; final long totalDuration;
Report(String name, long invocations, long totalDuration) { Report(String name, int invocations, long totalDuration) {
this.name = name; this.name = name;
this.invocations = invocations; this.invocations = invocations;
this.totalDuration = totalDuration; this.totalDuration = totalDuration;