Results 1 to 6 of 6
 04222013, 03:02 AM #1Member
 Join Date
 Mar 2010
 Posts
 18
 Rep Power
 0
How to calculate 95th percentile in Java
I am trying to calculate 95th Percentile from the data sets which I have populated in my below ConcurrentHashMap.
My Map will look like this In which
Java Code:key  means number of milliseconds value  means number of calls that took that much milliseconds
Java Code:Milliseconds Number 0 1702 1 15036 2 14262 3 13190 4 9137 5 5635 6 3742 7 2628 8 1899 9 1298 10 963 11 727 12 503 13 415 14 311 15 235 16 204 17 140 18 109 19 83 20 72
For example, from the above data sets, it means
Java Code:1702 calls came back in 0 milliseconds 15036 calls came back in 1 milliseconds
I know the algorithm will look something like this
Sum all values from your map, calculate 95% of the sum, iterate the map keys in ascending order keeping a running total of values, and when sum equals or exceeds the previously calculated 95% of the total sum, the key should be the 95th percentile.
But I am not able to plugin this algorithm in the Java code. Below is the map which will have above datasets.
Java Code:Map<Long, Long> histogram = new ConcurrentHashMap<Long, Long>
Java Code:private static void calculatePercentile() { for (Long time : CassandraTimer.histogram.keySet()) { } }
Any help will be appreciated.
 04222013, 03:53 AM #2
Re: How to calculate 95th percentile in Java
That is completely wrong. See Percentile  Wikipedia, the free encyclopedia.
Get in the habit of using standard Java naming conventions!
 04222013, 04:04 AM #3Member
 Join Date
 Mar 2010
 Posts
 18
 Rep Power
 0
Re: How to calculate 95th percentile in Java
I see. Yeah it looks like, I am wrong. Can you provide me an example how to calculate the 95th percentile for my question? Thanks for the help.
 04222013, 06:13 AM #4Member
 Join Date
 Apr 2010
 Location
 london UK
 Posts
 53
 Rep Power
 0
Re: How to calculate 95th percentile in Java
just count the >> numbers << together
0.95 times that number.
then look at the time that that sample took
so in your case , there were around 70.000 calls (quick count) so what time took the 66500 (shortest call?
(about 11 milli seconds )
 04222013, 08:02 AM #5
Re: How to calculate 95th percentile in Java
willemien is right. Using the first definition on that Wiki page, if you have n values and you want the 95th percentile, you would sort the values in ascending order and then take the value at index Math.round(n * 0.95).
Get in the habit of using standard Java naming conventions!
 04252013, 07:53 PM #6Member
 Join Date
 Apr 2010
 Location
 london UK
 Posts
 53
 Rep Power
 0
Similar Threads

how to calculate division in java
By noobplus in forum New To JavaReplies: 4Last Post: 03262012, 03:20 PM 
Program in Java To calculate GCD of n numbers.?
By ankitsinghal_89 in forum New To JavaReplies: 4Last Post: 02152011, 10:23 AM 
How to calculate remainder in JAVA (%)
By batista11b5 in forum New To JavaReplies: 25Last Post: 10252010, 08:39 AM 
Percentile by date
By Texas Longhorn in forum New To JavaReplies: 11Last Post: 06152010, 05:28 PM 
Calculate Tax in java
By toby in forum New To JavaReplies: 2Last Post: 07302007, 10:03 AM
Bookmarks