@Test public void testPercentileAlgorithm_Extremes() { PercentileSnapshot p = new PercentileSnapshot(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 800, 768, 657, 700, 867); System.out.println("0.01: " + p.getPercentile(0.01)); System.out.println("10th: " + p.getPercentile(10)); System.out.println("Median: " + p.getPercentile(50)); System.out.println("75th: " + p.getPercentile(75)); System.out.println("90th: " + p.getPercentile(90)); System.out.println("99th: " + p.getPercentile(99)); System.out.println("99.5th: " + p.getPercentile(99.5)); System.out.println("99.99: " + p.getPercentile(99.99)); Assert.assertEquals(2, p.getPercentile(50)); Assert.assertEquals(2, p.getPercentile(10)); Assert.assertEquals(2, p.getPercentile(75)); if (p.getPercentile(95) < 600) { fail("We expect the 90th to be over 600 to show the extremes but got: " + p.getPercentile(90)); } if (p.getPercentile(99) < 600) { fail("We expect the 99th to be over 600 to show the extremes but got: " + p.getPercentile(99)); } }
currentPercentileSnapshot = new PercentileSnapshot(allBuckets);
PercentileSnapshot ps = new PercentileSnapshot(1000, 1000, 1000, 2000, 1000, 500, 200, 200, 1600, 200, 1600, 1600);
currentPercentileSnapshot = new PercentileSnapshot(allBuckets);
/** * Force a reset so that percentiles start being gathered from scratch. */ public void reset() { /* no-op if disabled */ if (!enabled.get()) return; // clear buckets so we start over again buckets.clear(); // and also make sure the percentile snapshot gets reset currentPercentileSnapshot = new PercentileSnapshot(buckets.getArray()); }
@Test public void testPercentileAlgorithm_Median4() { PercentileSnapshot list = new PercentileSnapshot(300, 75, 125, 500, 100, 160, 180, 200, 210, 50, 170); // unsorted so it is expected to sort it for us // list.addValue(300); // 10 // list.addValue(75); // 2 // list.addValue(125); // 4 // list.addValue(500); // 11 // list.addValue(100); // 3 // list.addValue(160); // 5 // list.addValue(180); // 7 // list.addValue(200); // 8 // list.addValue(210); // 9 // list.addValue(50); // 1 // list.addValue(170); // 6 Assert.assertEquals(175, list.getPercentile(50)); }
@Test public void testPercentileAlgorithm_Median3() { PercentileSnapshot list = new PercentileSnapshot(50, 75, 100, 125, 160, 170, 180, 200, 210, 300, 500); // list.addValue(50); // 1 // list.addValue(75); // 2 // list.addValue(100); // 3 // list.addValue(125); // 4 // list.addValue(160); // 5 // list.addValue(170); // 6 // list.addValue(180); // 7 // list.addValue(200); // 8 // list.addValue(210); // 9 // list.addValue(300); // 10 // list.addValue(500); // 11 Assert.assertEquals(175, list.getPercentile(50)); }
public PercentileSnapshot getPercentileForValues(int... values) { return new PercentileSnapshot(values); }
/** * Force a reset so that percentiles start being gathered from scratch. */ public void reset() { /* no-op if disabled */ if (!enabled.get()) return; // clear buckets so we start over again buckets.clear(); // and also make sure the percentile snapshot gets reset currentPercentileSnapshot = new PercentileSnapshot(buckets.getArray()); }
@Test public void testPercentileAlgorithm_Median2() { PercentileSnapshot list = new PercentileSnapshot(100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 500); Assert.assertEquals(100, list.getPercentile(50)); }
@Test public void testPercentileAlgorithm_Median1() { PercentileSnapshot list = new PercentileSnapshot(100, 100, 100, 100, 200, 200, 200, 300, 300, 300, 300); Assert.assertEquals(200, list.getPercentile(50)); }