changeset 192:b96824f0578d

Shortcut percentile estimation in BootstrappedStatistics.
author shade
date Fri, 27 Sep 2013 11:42:32 +0400
parents 1a562b8e78b0
children f2babe7f11c0
files jmh-core/src/main/java/org/openjdk/jmh/util/internal/BootstrappedStatistics.java jmh-core/src/main/java/org/openjdk/jmh/util/internal/Statistics.java
diffstat 2 files changed, 15 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/internal/BootstrappedStatistics.java	Fri Sep 27 11:27:25 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/internal/BootstrappedStatistics.java	Fri Sep 27 11:42:32 2013 +0400
@@ -68,8 +68,7 @@
             for (int i = 0; i < values.length; i++) {
                 newValues[i] = values[rnd.nextInt(values.length)];
             }
-            Statistics s = new Statistics(newValues);
-            r.addValue(s.getPercentile(p));
+            r.addValue(Statistics.getPercentile(newValues, p));
         }
 
         return r;
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/internal/Statistics.java	Fri Sep 27 11:27:25 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/internal/Statistics.java	Fri Sep 27 11:42:32 2013 +0400
@@ -26,7 +26,7 @@
 
 import java.io.Serializable;
 import java.util.ArrayList;
-import java.util.Collections;
+import java.util.Arrays;
 import java.util.List;
 
 /**
@@ -189,10 +189,14 @@
             return Double.NaN;
         }
 
-        Collections.sort(values);
+        return getPercentile(getValues(), rank);
+    }
 
-        int n1 = (int) Math.floor(rank / 100.0D * getN());
-        int n2 = (int) Math.ceil(rank / 100.D * getN());
+    static double getPercentile(double[] values, double rank) {
+        Arrays.sort(values);
+
+        int n1 = (int) Math.floor(rank / 100.0D * values.length);
+        int n2 = (int) Math.ceil(rank / 100.D * values.length);
 
         if (n1 < 0) {
             n1 = 0;
@@ -202,16 +206,16 @@
             n2 = 0;
         }
 
-        if (n1 >= getN()) {
-            n1 = getN() - 1;
+        if (n1 >= values.length) {
+            n1 = values.length - 1;
         }
 
-        if (n2 >= getN()) {
-            n2 = getN() - 1;
+        if (n2 >= values.length) {
+            n2 = values.length - 1;
         }
 
-        double v1 = values.get(n1);
-        double v2 = values.get(n2);
+        double v1 = values[n1];
+        double v2 = values[n2];
 
         return v1 + (v2 - v1) / 2;
     }