Results 1 to 6 of 6
  1. #1
    raihan26 is offline Member
    Join Date
    Mar 2010
    Posts
    18
    Rep Power
    0

    Default 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
    Now I can calculate the 95th percentile by plugging the above data sets in the `Excel sheet`. But I was thinking to calculate the percentile in Java code.

    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>
    I am not sure what is the best way to calculate the percentile in Java. I am not sure whether I am algorithm is also correct or not.


    Java Code:
        private static void calculatePercentile() {
        
        	for (Long time : CassandraTimer.histogram.keySet()) {
        
        	
        	}
        
        }
    Can anyone provide some example how to do that?

    Any help will be appreciated.

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: How to calculate 95th percentile in Java

    Quote Originally Posted by raihan26 View Post
    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.
    That is completely wrong. See Percentile - Wikipedia, the free encyclopedia.
    Get in the habit of using standard Java naming conventions!

  3. #3
    raihan26 is offline Member
    Join Date
    Mar 2010
    Posts
    18
    Rep Power
    0

    Default 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.

  4. #4
    willemien is offline Member
    Join Date
    Apr 2010
    Location
    london UK
    Posts
    53
    Rep Power
    0

    Default 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 )

  5. #5
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default 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!

  6. #6
    willemien is offline Member
    Join Date
    Apr 2010
    Location
    london UK
    Posts
    53
    Rep Power
    0

    Default Re: How to calculate 95th percentile in Java

    Quote Originally Posted by kjkrum View Post
    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).

Similar Threads

  1. how to calculate division in java
    By noobplus in forum New To Java
    Replies: 4
    Last Post: 03-26-2012, 03:20 PM
  2. Program in Java To calculate GCD of n numbers.?
    By ankitsinghal_89 in forum New To Java
    Replies: 4
    Last Post: 02-15-2011, 10:23 AM
  3. How to calculate remainder in JAVA (%)
    By batista11b5 in forum New To Java
    Replies: 25
    Last Post: 10-25-2010, 08:39 AM
  4. Percentile by date
    By Texas Longhorn in forum New To Java
    Replies: 11
    Last Post: 06-15-2010, 05:28 PM
  5. Calculate Tax in java
    By toby in forum New To Java
    Replies: 2
    Last Post: 07-30-2007, 10:03 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •