Example usage for java.util LongSummaryStatistics getAverage

List of usage examples for java.util LongSummaryStatistics getAverage

Introduction

In this page you can find the example usage for java.util LongSummaryStatistics getAverage.

Prototype

public final double getAverage() 

Source Link

Document

Returns the arithmetic mean of values recorded, or zero if no values have been recorded.

Usage

From source file:de.tynne.benchmarksuite.Main.java

private static void checkNano(PrintStream ps) {
    List<Long> diffs = new ArrayList<>();

    nanoNullLoop(1000000, diffs);//  www.  j  av a  2 s. co  m
    diffs.clear();
    nanoNullLoop(1000000, diffs);

    LongSummaryStatistics statistics = diffs.stream().mapToLong(l -> l).summaryStatistics();

    ps.printf("min=%d, avg=%g, max=%d\n", statistics.getMin(), statistics.getAverage(), statistics.getMax());
}

From source file:org.apache.nifi.cluster.coordination.http.replication.ThreadPoolRequestReplicator.java

private void logTimingInfo(final AsyncClusterResponse response) {
    // Calculate min, max, mean for the requests
    final LongSummaryStatistics stats = response.getNodesInvolved().stream()
            .map(p -> response.getNodeResponse(p).getRequestDuration(TimeUnit.MILLISECONDS))
            .collect(Collectors.summarizingLong(Long::longValue));

    final StringBuilder sb = new StringBuilder();
    sb.append("Node Responses for ").append(response.getMethod()).append(" ").append(response.getURIPath())
            .append(" (Request ID ").append(response.getRequestIdentifier()).append("):\n");
    for (final NodeIdentifier node : response.getNodesInvolved()) {
        sb.append(node).append(": ")
                .append(response.getNodeResponse(node).getRequestDuration(TimeUnit.MILLISECONDS))
                .append(" millis\n");
    }/*from  w w w.ja  va2 s.c  om*/

    logger.debug("For {} {} (Request ID {}), minimum response time = {}, max = {}, average = {} ms",
            response.getMethod(), response.getURIPath(), response.getRequestIdentifier(), stats.getMin(),
            stats.getMax(), stats.getAverage());
    logger.debug(sb.toString());
}