All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.undefinedlabs.scope.rules.extractor.OpsPerTimeScopeBenchmarkStatisticsExtractor Maven / Gradle / Ivy

Go to download

Scope is a APM for tests to give engineering teams unprecedented visibility into their CI process to quickly identify, troubleshoot and fix failed builds. This artifact contains the classes to instrument the Java JMH Benchmark Framework.

There is a newer version: 0.15.1-beta.2
Show newest version
package com.undefinedlabs.scope.rules.extractor;

import com.undefinedlabs.scope.rules.model.ScopeBenchmarkStatistics;
import org.openjdk.jmh.results.Result;
import org.openjdk.jmh.util.Statistics;

public class OpsPerTimeScopeBenchmarkStatisticsExtractor
    extends AbstractScopeBenchmarkStatisticsExtractor {

  public static final ScopeBenchmarkStatisticsExtractor INSTANCE =
      new OpsPerTimeScopeBenchmarkStatisticsExtractor();

  private OpsPerTimeScopeBenchmarkStatisticsExtractor() {}

  @Override
  public ScopeBenchmarkStatistics extract(Result result) {
    final ScopeBenchmarkStatistics.Builder builder = newBuilder();

    final Statistics jmhStats = result.getStatistics();

    builder.withSampleCount(result.getSampleCount());
    builder.withScore(inverse(result.getScore()));
    builder.withScoreConfidence(inverse(result.getScoreConfidence()));
    builder.withScoreError(inverse(result.getScore()));

    if (jmhStats != null) {
      builder.withMin(inverse(jmhStats.getMin()));
      builder.withMean(inverse(jmhStats.getMean()));
      builder.withMax(inverse(jmhStats.getMax()));
      builder.withStdDev(inverse(jmhStats.getStandardDeviation()));
      builder.withVariance(inverse(jmhStats.getVariance()));
      builder.withP00(inverse(jmhStats.getPercentile(0)));
      builder.withP50(inverse(jmhStats.getPercentile(50)));
      builder.withP90(inverse(jmhStats.getPercentile(90)));
      builder.withP95(inverse(jmhStats.getPercentile(95)));
      builder.withP99(inverse(jmhStats.getPercentile(99)));
      builder.withP100(inverse(jmhStats.getPercentile(100)));
    }

    return builder.build();
  }

  private double[] inverse(final double[] numberArray) {
    if (numberArray == null || numberArray.length == 0 || Double.isNaN(numberArray[0])) {
      return numberArray;
    }

    for (int i = 0; i < numberArray.length; i++) {
      numberArray[i] = inverse(numberArray[i]);
    }

    return numberArray;
  }

  private double inverse(final double number) {
    if (Double.isNaN(number)) {
      return number;
    }

    return Math.pow(number, -1);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy