calculating the percentile in java

Solutions on MaxInterview for calculating the percentile in java by the best coders in the world

showing results for - "calculating the percentile in java"
Laura
11 May 2018
1/**
2 * A simple method to log 95th percentile information
3 */
4private static void logPercentileInfo() {
5
6    double total = 0;
7    for (Map.Entry<Long, Long> entry : CassandraTimer.histogram.entrySet()) {
8        long value = entry.getKey() * entry.getValue();
9        total += value;
10    }
11
12    double sum = 0.95*total;
13
14    double totalSum = 0;
15
16    SortedSet<Long> keys = new TreeSet<Long>(CassandraTimer.histogram.keySet());
17    for (long key : keys) {
18
19        totalSum += CassandraTimer.histogram.get(key);
20
21        if(totalSum >= sum) {
22           //this is the 95th percentile I guess
23            System.out.println(key);
24        }
25    }
26
27}
Eleonora
16 Aug 2020
1for (i=0, sum=0; i<n; i++) sum += Number[i];
2tot = sum;
3for (i=0, sum=0; i<n && sum < 0.95*tot; i++) sum += Number[i];
4// i is about it
Claudia
02 Oct 2020
1  public static long[] percentiles(long[] latencies, double... percentiles) {
2    Arrays.sort(latencies, 0, latencies.length);
3    long[] values = new long[percentiles.length];
4    for (int i = 0; i < percentiles.length; i++) {
5      int index = (int) (percentiles[i] * latencies.length);
6      values[i] = latencies[index];
7    }
8    return values;
9  }
queries leading to this page
calculate percentage javapercentile javapercentage in javacalculating the percentile in javaworking out percentages in javajava calculate percentage of a numbercalculate 90th percentile in javajava percentage calculate in javahow to make percent of a number in javajava calculate percentmethod to determine percentile in javajava what is percentget percent javacalculate percentage in javapercent in javahow to calculate the percentage in javahow to write percetile function in javapercentage calculation in java programcalculate 90th percentile in java using librariespercentage calculation in javahow to calculate percentage in javapercent s in javajava calculate percentage from integersjava percentage calculationjava percentile formulapercentage calculate in javawhat is percent s in javajava calculate percentagecalculate percentage java code percent calculation in javawhat is a percent in java dojava get percentilehow to write percentile function in javahow to get the percentile in javajava percentile calculationjava code to calculate percentage of amounthow to calculate a percentile in javajava percentwhat does percent do in javafind the percentage javahow to find percentage in javapercentile formula in javajava calculate percentilefinding percentiles in javahow to compute percentage in javaworking out percentage in java java how to calculate percentagehow to return a percent in javapercent javajava get percentage of numbercalculating the percentile in java