org.apache.commons.math3.stat.descriptive.StatisticalSummary Java Examples

The following examples show how to use org.apache.commons.math3.stat.descriptive.StatisticalSummary. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Aggregation.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public StatisticalSummary apply(final List<V> values) {
    stat.clear();
    double v;
    for (Object value : values) {
        if (value != null) {
            if (value instanceof Boolean) {
                value = Boolean.class.cast(value) ? 1 : 0;
            }
            v = Number.class.cast(value).doubleValue();
            if (!Double.isNaN(v))
                stat.addValue(v);
        }
    }
    return stat.getSummary();
}
 
Example #2
Source File: PerfTestUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Timing.
 *
 * @param repeatChunk Each timing measurement will done done for that
 * number of repeats of the code.
 * @param repeatStat Timing will be averaged over that number of runs.
 * @param runGC Call {@code System.gc()} between each timed block. When
 * set to {@code true}, the test will run much slower.
 * @param methods Codes being timed.
 * @return for each of the given {@code methods}, a
 * {@link StatisticalSummary} of the average times (in milliseconds)
 * taken by a single call to the {@code call} method (i.e. the time
 * taken by each timed block divided by {@code repeatChunk}).
 */
public static StatisticalSummary[] time(int repeatChunk,
                                        int repeatStat,
                                        boolean runGC,
                                        Callable<Double> ... methods) {
    final double[][][] times = timesAndResults(repeatChunk,
                                               repeatStat,
                                               runGC,
                                               methods);

    final int len = methods.length;
    final StatisticalSummary[] stats = new StatisticalSummary[len];
    for (int j = 0; j < len; j++) {
        final SummaryStatistics s = new SummaryStatistics();
        for (int k = 0; k < repeatStat; k++) {
            s.addValue(times[j][k][0]);
        }
        stats[j] = s.getSummary();
    }

    return stats;
}
 
Example #3
Source File: PerfTestUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Timing.
 *
 * @param repeatChunk Each timing measurement will done done for that
 * number of repeats of the code.
 * @param repeatStat Timing will be averaged over that number of runs.
 * @param runGC Call {@code System.gc()} between each timed block. When
 * set to {@code true}, the test will run much slower.
 * @param methods Codes being timed.
 * @return for each of the given {@code methods}, a
 * {@link StatisticalSummary} of the average times (in milliseconds)
 * taken by a single call to the {@code call} method (i.e. the time
 * taken by each timed block divided by {@code repeatChunk}).
 */
public static StatisticalSummary[] time(int repeatChunk,
                                        int repeatStat,
                                        boolean runGC,
                                        Callable<Double> ... methods) {
    final double[][][] times = timesAndResults(repeatChunk,
                                               repeatStat,
                                               runGC,
                                               methods);

    final int len = methods.length;
    final StatisticalSummary[] stats = new StatisticalSummary[len];
    for (int j = 0; j < len; j++) {
        final SummaryStatistics s = new SummaryStatistics();
        for (int k = 0; k < repeatStat; k++) {
            s.addValue(times[j][k][0]);
        }
        stats[j] = s.getSummary();
    }

    return stats;
}
 
Example #4
Source File: PerfTestUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Timing.
 *
 * @param repeatChunk Each timing measurement will done done for that
 * number of repeats of the code.
 * @param repeatStat Timing will be averaged over that number of runs.
 * @param runGC Call {@code System.gc()} between each timed block. When
 * set to {@code true}, the test will run much slower.
 * @param methods Codes being timed.
 * @return for each of the given {@code methods}, a
 * {@link StatisticalSummary} of the average times (in milliseconds)
 * taken by a single call to the {@code call} method (i.e. the time
 * taken by each timed block divided by {@code repeatChunk}).
 */
public static StatisticalSummary[] time(int repeatChunk,
                                        int repeatStat,
                                        boolean runGC,
                                        Callable<Double> ... methods) {
    final double[][][] times = timesAndResults(repeatChunk,
                                               repeatStat,
                                               runGC,
                                               methods);

    final int len = methods.length;
    final StatisticalSummary[] stats = new StatisticalSummary[len];
    for (int j = 0; j < len; j++) {
        final SummaryStatistics s = new SummaryStatistics();
        for (int k = 0; k < repeatStat; k++) {
            s.addValue(times[j][k][0]);
        }
        stats[j] = s.getSummary();
    }

    return stats;
}
 
Example #5
Source File: PerfTestUtils.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Timing.
 *
 * @param repeatChunk Each timing measurement will done done for that
 * number of repeats of the code.
 * @param repeatStat Timing will be averaged over that number of runs.
 * @param runGC Call {@code System.gc()} between each timed block. When
 * set to {@code true}, the test will run much slower.
 * @param methods Codes being timed.
 * @return for each of the given {@code methods}, a
 * {@link StatisticalSummary} of the average times (in milliseconds)
 * taken by a single call to the {@code call} method (i.e. the time
 * taken by each timed block divided by {@code repeatChunk}).
 */
public static StatisticalSummary[] time(int repeatChunk,
                                        int repeatStat,
                                        boolean runGC,
                                        Callable<Double> ... methods) {
    final double[][][] times = timesAndResults(repeatChunk,
                                               repeatStat,
                                               runGC,
                                               methods);

    final int len = methods.length;
    final StatisticalSummary[] stats = new StatisticalSummary[len];
    for (int j = 0; j < len; j++) {
        final SummaryStatistics s = new SummaryStatistics();
        for (int k = 0; k < repeatStat; k++) {
            s.addValue(times[j][k][0]);
        }
        stats[j] = s.getSummary();
    }

    return stats;
}
 
Example #6
Source File: TestUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see org.apache.commons.math3.stat.inference.TTest#tTest(org.apache.commons.math3.stat.descriptive.StatisticalSummary, org.apache.commons.math3.stat.descriptive.StatisticalSummary, double)
 */
public static boolean tTest(final StatisticalSummary sampleStats1,
                            final StatisticalSummary sampleStats2,
                            final double alpha)
    throws NullArgumentException, NumberIsTooSmallException,
    OutOfRangeException, MaxCountExceededException {
    return T_TEST.tTest(sampleStats1, sampleStats2, alpha);
}
 
Example #7
Source File: TTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check sample data.
 *
 * @param stat Statistical summary.
 * @throws NullArgumentException if {@code data} is {@code null}.
 * @throws NumberIsTooSmallException if there is not enough sample data.
 */
private void checkSampleData(final StatisticalSummary stat)
    throws NullArgumentException, NumberIsTooSmallException {

    if (stat == null) {
        throw new NullArgumentException();
    }
    if (stat.getN() < 2) {
        throw new NumberIsTooSmallException(
                LocalizedFormats.INSUFFICIENT_DATA_FOR_T_STATISTIC,
                stat.getN(), 2, true);
    }

}
 
Example #8
Source File: TestUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see org.apache.commons.math3.stat.inference.TTest#tTest(double, org.apache.commons.math3.stat.descriptive.StatisticalSummary, double)
 */
public static boolean tTest(final double mu, final StatisticalSummary sampleStats,
                            final double alpha)
    throws NullArgumentException, NumberIsTooSmallException,
    OutOfRangeException, MaxCountExceededException {
    return T_TEST.tTest(mu, sampleStats, alpha);
}
 
Example #9
Source File: TTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check sample data.
 *
 * @param stat Statistical summary.
 * @throws NullArgumentException if {@code data} is {@code null}.
 * @throws NumberIsTooSmallException if there is not enough sample data.
 */
private void checkSampleData(final StatisticalSummary stat)
    throws NullArgumentException, NumberIsTooSmallException {

    if (stat == null) {
        throw new NullArgumentException();
    }
    if (stat.getN() < 2) {
        throw new NumberIsTooSmallException(
                LocalizedFormats.INSUFFICIENT_DATA_FOR_T_STATISTIC,
                stat.getN(), 2, true);
    }

}
 
Example #10
Source File: TTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check sample data.
 *
 * @param stat Statistical summary.
 * @throws NullArgumentException if {@code data} is {@code null}.
 * @throws NumberIsTooSmallException if there is not enough sample data.
 */
private void checkSampleData(final StatisticalSummary stat)
    throws NullArgumentException, NumberIsTooSmallException {

    if (stat == null) {
        throw new NullArgumentException();
    }
    if (stat.getN() < 2) {
        throw new NumberIsTooSmallException(
                LocalizedFormats.INSUFFICIENT_DATA_FOR_T_STATISTIC,
                stat.getN(), 2, true);
    }

}
 
Example #11
Source File: TestUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see org.apache.commons.math3.stat.inference.TTest#tTest(org.apache.commons.math3.stat.descriptive.StatisticalSummary, org.apache.commons.math3.stat.descriptive.StatisticalSummary)
 */
public static double tTest(final StatisticalSummary sampleStats1,
                           final StatisticalSummary sampleStats2)
    throws NullArgumentException, NumberIsTooSmallException,
    MaxCountExceededException {
    return T_TEST.tTest(sampleStats1, sampleStats2);
}
 
Example #12
Source File: TestUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see org.apache.commons.math3.stat.inference.TTest#tTest(org.apache.commons.math3.stat.descriptive.StatisticalSummary, org.apache.commons.math3.stat.descriptive.StatisticalSummary)
 */
public static double tTest(final StatisticalSummary sampleStats1,
                           final StatisticalSummary sampleStats2)
    throws NullArgumentException, NumberIsTooSmallException,
    MaxCountExceededException {
    return T_TEST.tTest(sampleStats1, sampleStats2);
}
 
Example #13
Source File: TestUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see org.apache.commons.math3.stat.inference.TTest#tTest(org.apache.commons.math3.stat.descriptive.StatisticalSummary, org.apache.commons.math3.stat.descriptive.StatisticalSummary, double)
 */
public static boolean tTest(final StatisticalSummary sampleStats1,
                            final StatisticalSummary sampleStats2,
                            final double alpha)
    throws NullArgumentException, NumberIsTooSmallException,
    OutOfRangeException, MaxCountExceededException {
    return T_TEST.tTest(sampleStats1, sampleStats2, alpha);
}
 
Example #14
Source File: TestUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see org.apache.commons.math3.stat.inference.TTest#tTest(org.apache.commons.math3.stat.descriptive.StatisticalSummary, org.apache.commons.math3.stat.descriptive.StatisticalSummary, double)
 */
public static boolean tTest(final StatisticalSummary sampleStats1,
                            final StatisticalSummary sampleStats2,
                            final double alpha)
    throws NullArgumentException, NumberIsTooSmallException,
    OutOfRangeException, MaxCountExceededException {
    return T_TEST.tTest(sampleStats1, sampleStats2, alpha);
}
 
Example #15
Source File: TestUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see org.apache.commons.math3.stat.inference.TTest#tTest(org.apache.commons.math3.stat.descriptive.StatisticalSummary, org.apache.commons.math3.stat.descriptive.StatisticalSummary, double)
 */
public static boolean tTest(final StatisticalSummary sampleStats1,
                            final StatisticalSummary sampleStats2,
                            final double alpha)
    throws NullArgumentException, NumberIsTooSmallException,
    OutOfRangeException, MaxCountExceededException {
    return T_TEST.tTest(sampleStats1, sampleStats2, alpha);
}
 
Example #16
Source File: Aggregation.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public static DataFrame describe(final DataFrame df) {
    final DataFrame desc = new DataFrame();
    for (final Column col : df.getColumns()) {
         Column ncol = new Column(col.getName(), DataType.DOUBLE);
        for (final Object row : df.getIndex()) {
            final Object value = df.getValue(row, col);
            if (value instanceof StatisticalSummary) {
                if (!desc.getColumns().contains(ncol)) {                       
                    desc.addColumn(ncol);
                    if (desc.isEmpty()) {
                        for (final Object r : df.getIndex()) {
                            for (final Object stat : Arrays.asList("count", "mean", "std", "var", "max", "min")) {
                                final Object name = name(df, r, stat);
                                desc.append(name, new ArrayList<>());
                            }
                        }
                    }
                }

                final StatisticalSummary summary = StatisticalSummary.class.cast(value);
                desc.setValue(name(df, row, "count"), ncol,  summary.getN());
                desc.setValue(name(df, row, "mean"), ncol, summary.getMean());
                desc.setValue(name(df, row, "std"), ncol, summary.getStandardDeviation());
                desc.setValue(name(df, row, "var"), ncol, summary.getVariance());
                desc.setValue(name(df, row, "max"), ncol, summary.getMax());
                desc.setValue(name(df, row, "min"), ncol, summary.getMin());
            }
        }
    }
    return desc;
}
 
Example #17
Source File: TTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check sample data.
 *
 * @param stat Statistical summary.
 * @throws NullArgumentException if {@code data} is {@code null}.
 * @throws NumberIsTooSmallException if there is not enough sample data.
 */
private void checkSampleData(final StatisticalSummary stat)
    throws NullArgumentException, NumberIsTooSmallException {

    if (stat == null) {
        throw new NullArgumentException();
    }
    if (stat.getN() < 2) {
        throw new NumberIsTooSmallException(
                LocalizedFormats.INSUFFICIENT_DATA_FOR_T_STATISTIC,
                stat.getN(), 2, true);
    }

}
 
Example #18
Source File: TabletSummaryTest.java    From timely with Apache License 2.0 5 votes vote down vote up
@Test
public void aggregateComputes() {
    long a1 = TimeUnit.HOURS.toMillis(1);
    long a2 = TimeUnit.HOURS.toMillis(2);

    long ts1 = DEFAULT_TIME_MILLIS - a1;
    long ts2 = DEFAULT_TIME_MILLIS - a2;

    Text r1 = new Text(MetricAdapter.encodeRowKey("sys.cpu", ts1));
    Text r2 = new Text(MetricAdapter.encodeRowKey("sys.cpu", ts2));
    Text r3 = new Text(MetricAdapter.encodeRowKey("sys.mem", ts1));

    MetadataAccumulator.Entry e1 = new MetadataAccumulator.Entry(r1);
    MetadataAccumulator.Entry e2 = new MetadataAccumulator.Entry(r2);
    MetadataAccumulator.Entry e3 = new MetadataAccumulator.Entry(r3);

    e1.addFile(800);
    e1.addFile(100);
    e2.addFile(100);
    e2.addFile(200);
    e1.addFile(500);

    // @formatter:off
    TabletSummary summary = TabletSummary.newBuilder(Lists.newArrayList(e1, e2, e3))
            .currentTime(DEFAULT_TIME_MILLIS)
            .disableTabletRowCheckFilter()
            .build();

    // @formatter:on
    Map<TabletStatisticType, StatisticalSummary> map = summary.aggregateSummary();
    StatisticalSummary size = map.get(TabletStatisticType.SIZE);
    StatisticalSummary time = map.get(TabletStatisticType.TIME);

    assertEquals(1700, (long) size.getSum());
    assertEquals(a2, (long) time.getMax());
    assertEquals(a1, (long) time.getMin());
}
 
Example #19
Source File: LazzyLoggerImplPerfTest.java    From metron with Apache License 2.0 5 votes vote down vote up
private StatisticalSummary runTrial(int reps, Operation operation) {
  DescriptiveStatistics stats = new DescriptiveStatistics();
  long trialTime = timeOperation(() -> {
    for (int i = 0; i < reps; i++) {
      long time = timeOperation(operation);
      stats.addValue(time / NANO_TO_MILLIS);
    }
  });
  System.out.println("Total trial time (ms): " + (trialTime / NANO_TO_MILLIS));
  return stats;
}
 
Example #20
Source File: TestUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see org.apache.commons.math3.stat.inference.TTest#tTest(org.apache.commons.math3.stat.descriptive.StatisticalSummary, org.apache.commons.math3.stat.descriptive.StatisticalSummary)
 */
public static double tTest(final StatisticalSummary sampleStats1,
                           final StatisticalSummary sampleStats2)
    throws NullArgumentException, NumberIsTooSmallException,
    MaxCountExceededException {
    return T_TEST.tTest(sampleStats1, sampleStats2);
}
 
Example #21
Source File: TestUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @see org.apache.commons.math3.stat.inference.TTest#tTest(org.apache.commons.math3.stat.descriptive.StatisticalSummary, org.apache.commons.math3.stat.descriptive.StatisticalSummary, double)
 */
public static boolean tTest(final StatisticalSummary sampleStats1,
                            final StatisticalSummary sampleStats2,
                            final double alpha)
    throws NullArgumentException, NumberIsTooSmallException,
    OutOfRangeException, MaxCountExceededException {
    return T_TEST.tTest(sampleStats1, sampleStats2, alpha);
}
 
Example #22
Source File: TestUtils.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see org.apache.commons.math3.stat.inference.TTest#tTest(double, org.apache.commons.math3.stat.descriptive.StatisticalSummary)
 */
public static double tTest(final double mu, final StatisticalSummary sampleStats)
    throws NullArgumentException, NumberIsTooSmallException,
    MaxCountExceededException {
    return T_TEST.tTest(mu, sampleStats);
}
 
Example #23
Source File: PerfTestUtils.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Timing and report (to standard output) the average time and standard
 * deviation of a single call.
 * The timing is performed by calling the
 * {@link #time(int,int,boolean,Callable[]) time} method.
 *
 * @param title Title of the test (for the report).
 * @param repeatChunk Each timing measurement will done done for that
 * number of repeats of the code.
 * @param repeatStat Timing will be averaged over that number of runs.
 * @param runGC Call {@code System.gc()} between each timed block. When
 * set to {@code true}, the test will run much slower.
 * @param methods Codes being timed.
 * @return for each of the given {@code methods}, a statistics of the
 * average times (in milliseconds) taken by a single call to the
 * {@code call} method (i.e. the time taken by each timed block divided
 * by {@code repeatChunk}).
 */
public static StatisticalSummary[] timeAndReport(String title,
                                                 int repeatChunk,
                                                 int repeatStat,
                                                 boolean runGC,
                                                 RunTest ... methods) {
    // Header format.
    final String hFormat = "%s (calls per timed block: %d, timed blocks: %d, time unit: ms)";

    // Width of the longest name.
    int nameLength = 0;
    for (RunTest m : methods) {
        int len = m.getName().length();
        if (len > nameLength) {
            nameLength = len;
        }
    }
    final String nameLengthFormat = "%" + nameLength + "s";

    // Column format.
    final String cFormat = nameLengthFormat + " %14s %14s %10s %10s %15s";
    // Result format.
    final String format = nameLengthFormat + " %.8e %.8e %.4e %.4e % .8e";

    System.out.println(String.format(hFormat,
                                     title,
                                     repeatChunk,
                                     repeatStat));
    System.out.println(String.format(cFormat,
                                     "name",
                                     "time/call",
                                     "std error",
                                     "total time",
                                     "ratio",
                                     "difference"));
    final StatisticalSummary[] time = time(repeatChunk,
                                           repeatStat,
                                           runGC,
                                           methods);
    final double refSum = time[0].getSum() * repeatChunk;
    for (int i = 0, max = time.length; i < max; i++) {
        final StatisticalSummary s = time[i];
        final double sum = s.getSum() * repeatChunk;
        System.out.println(String.format(format,
                                         methods[i].getName(),
                                         s.getMean(),
                                         s.getStandardDeviation(),
                                         sum,
                                         sum / refSum,
                                         sum - refSum));
    }

    return time;
}
 
Example #24
Source File: LazzyLoggerImplPerfTest.java    From metron with Apache License 2.0 4 votes vote down vote up
@Test
@Disabled
public void calcTimes() {
  Map<String, Object> smallMap = new HashMap<>();
  for (int i = 0; i < 10; i++) {
    smallMap.put("key" + i, RandomStringUtils.randomAlphabetic(10));
  }
  Map<String, Object> largeMap = new HashMap<>();
  for (int i = 0; i < 500; i++) {
    largeMap.put("key" + i, RandomStringUtils.randomAlphabetic(1000));
  }
  JSONObject largeObject = new JSONObject(largeMap);
  JSONObject smallObject = new JSONObject(smallMap);
  int reps = 1000;

  StatisticalSummary summary = runTrial(reps, () -> {
    LOG.trace("Writing message {} to path: {}", smallObject.toJSONString(), PATH);
  });
  printSummary(String.format("Small object %s times", reps), summary);

  summary = runTrial(reps, () -> {
    LOG.trace("Writing message {} to path: {}", () -> smallObject.toJSONString(), () -> PATH);
  });
  printSummary(String.format("Small object %s times using lazy logging", reps), summary);


  summary = runTrial(reps, () -> {
    LOG.trace("Writing message {} to path: {}", largeObject.toJSONString(), PATH);
  });
  printSummary(String.format("Large object %s times", reps), summary);

  summary = runTrial(reps, () -> {
    LOG.trace("Writing message {} to path: {}", () -> largeObject.toJSONString(), () -> PATH);
  });
  printSummary(String.format("Large object %s times using lazy logging", reps), summary);

  summary = runTrial(reps, () -> {
    LOG.trace("Writing message {} to path: {}", "hello", PATH);
  });
  printSummary(String.format("Simple string %s times", reps), summary);

  summary = runTrial(reps, () -> {
    LOG.trace("Writing message {} to path: {}", () -> "hello", () -> PATH);
  });
  printSummary(String.format("Simple string %s times using lazy logging", reps), summary);
}
 
Example #25
Source File: TestUtils.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see org.apache.commons.math3.stat.inference.TTest#tTest(double, org.apache.commons.math3.stat.descriptive.StatisticalSummary)
 */
public static double tTest(final double mu, final StatisticalSummary sampleStats)
    throws NullArgumentException, NumberIsTooSmallException,
    MaxCountExceededException {
    return T_TEST.tTest(mu, sampleStats);
}
 
Example #26
Source File: TestUtils.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see org.apache.commons.math3.stat.inference.TTest#t(org.apache.commons.math3.stat.descriptive.StatisticalSummary, org.apache.commons.math3.stat.descriptive.StatisticalSummary)
 */
public static double t(final StatisticalSummary sampleStats1,
                       final StatisticalSummary sampleStats2)
    throws NullArgumentException, NumberIsTooSmallException {
    return T_TEST.t(sampleStats1, sampleStats2);
}
 
Example #27
Source File: PerfTestUtils.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Timing and report (to standard output) the average time and standard
 * deviation of a single call.
 * The timing is performed by calling the
 * {@link #time(int,int,boolean,Callable[]) time} method.
 *
 * @param title Title of the test (for the report).
 * @param repeatChunk Each timing measurement will done done for that
 * number of repeats of the code.
 * @param repeatStat Timing will be averaged over that number of runs.
 * @param runGC Call {@code System.gc()} between each timed block. When
 * set to {@code true}, the test will run much slower.
 * @param methods Codes being timed.
 * @return for each of the given {@code methods}, a statistics of the
 * average times (in milliseconds) taken by a single call to the
 * {@code call} method (i.e. the time taken by each timed block divided
 * by {@code repeatChunk}).
 */
public static StatisticalSummary[] timeAndReport(String title,
                                                 int repeatChunk,
                                                 int repeatStat,
                                                 boolean runGC,
                                                 RunTest ... methods) {
    // Header format.
    final String hFormat = "%s (calls per timed block: %d, timed blocks: %d, time unit: ms)";

    // Width of the longest name.
    int nameLength = 0;
    for (RunTest m : methods) {
        int len = m.getName().length();
        if (len > nameLength) {
            nameLength = len;
        }
    }
    final String nameLengthFormat = "%" + nameLength + "s";

    // Column format.
    final String cFormat = nameLengthFormat + " %14s %14s %10s %10s %15s";
    // Result format.
    final String format = nameLengthFormat + " %.8e %.8e %.4e %.4e % .8e";

    System.out.println(String.format(hFormat,
                                     title,
                                     repeatChunk,
                                     repeatStat));
    System.out.println(String.format(cFormat,
                                     "name",
                                     "time/call",
                                     "std error",
                                     "total time",
                                     "ratio",
                                     "difference"));
    final StatisticalSummary[] time = time(repeatChunk,
                                           repeatStat,
                                           runGC,
                                           methods);
    final double refSum = time[0].getSum() * repeatChunk;
    for (int i = 0, max = time.length; i < max; i++) {
        final StatisticalSummary s = time[i];
        final double sum = s.getSum() * repeatChunk;
        System.out.println(String.format(format,
                                         methods[i].getName(),
                                         s.getMean(),
                                         s.getStandardDeviation(),
                                         sum,
                                         sum / refSum,
                                         sum - refSum));
    }

    return time;
}
 
Example #28
Source File: PerfTestUtils.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Timing and report (to standard output) the average time and standard
 * deviation of a single call.
 * The timing is performed by calling the
 * {@link #time(int,int,boolean,Callable[]) time} method.
 *
 * @param title Title of the test (for the report).
 * @param repeatChunk Each timing measurement will done done for that
 * number of repeats of the code.
 * @param repeatStat Timing will be averaged over that number of runs.
 * @param runGC Call {@code System.gc()} between each timed block. When
 * set to {@code true}, the test will run much slower.
 * @param methods Codes being timed.
 * @return for each of the given {@code methods}, a statistics of the
 * average times (in milliseconds) taken by a single call to the
 * {@code call} method (i.e. the time taken by each timed block divided
 * by {@code repeatChunk}).
 */
@SuppressWarnings("boxing")
public static StatisticalSummary[] timeAndReport(String title,
                                                 int repeatChunk,
                                                 int repeatStat,
                                                 boolean runGC,
                                                 RunTest ... methods) {
    // Header format.
    final String hFormat = "%s (calls per timed block: %d, timed blocks: %d, time unit: ms)";

    // Width of the longest name.
    int nameLength = 0;
    for (RunTest m : methods) {
        int len = m.getName().length();
        if (len > nameLength) {
            nameLength = len;
        }
    }
    final String nameLengthFormat = "%" + nameLength + "s";

    // Column format.
    final String cFormat = nameLengthFormat + " %14s %14s %10s %10s %15s";
    // Result format.
    final String format = nameLengthFormat + " %.8e %.8e %.4e %.4e % .8e";

    System.out.println(String.format(hFormat,
                                     title,
                                     repeatChunk,
                                     repeatStat));
    System.out.println(String.format(cFormat,
                                     "name",
                                     "time/call",
                                     "std error",
                                     "total time",
                                     "ratio",
                                     "difference"));
    final StatisticalSummary[] time = time(repeatChunk,
                                           repeatStat,
                                           runGC,
                                           methods);
    final double refSum = time[0].getSum() * repeatChunk;
    for (int i = 0, max = time.length; i < max; i++) {
        final StatisticalSummary s = time[i];
        final double sum = s.getSum() * repeatChunk;
        System.out.println(String.format(format,
                                         methods[i].getName(),
                                         s.getMean(),
                                         s.getStandardDeviation(),
                                         sum,
                                         sum / refSum,
                                         sum - refSum));
    }

    return time;
}
 
Example #29
Source File: TestUtils.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @see org.apache.commons.math3.stat.inference.TTest#t(double, org.apache.commons.math3.stat.descriptive.StatisticalSummary)
 */
public static double t(final double mu, final StatisticalSummary sampleStats)
    throws NullArgumentException, NumberIsTooSmallException {
    return T_TEST.t(mu, sampleStats);
}
 
Example #30
Source File: TabletStatistic.java    From timely with Apache License 2.0 4 votes vote down vote up
public StatisticalSummary getSummary(TabletStatisticType statType) {
    return this.stats.getOrDefault(statType, new SummaryStatistics());
}