Skip to content

Commit

Permalink
Merge pull request #1335 from eduardmanas/benchmark2
Browse files Browse the repository at this point in the history
Remove BenchmarkResultAggregator
  • Loading branch information
danieldietrich committed May 22, 2016
2 parents 4422405 + 595c1de commit d674941
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 172 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package javaslang.benchmark;

import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.results.RunResult;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openjdk.jmh.runner.options.TimeValue;

import java.util.Collection;
import java.util.concurrent.TimeUnit;

public class JmhRunner {
private static final int WARMUP_ITERATIONS = 10;
private static final int MEASUREMENT_ITERATIONS = 40;

private static final int QUICK_WARMUP_ITERATIONS = 5;
private static final int QUICK_MEASUREMENT_ITERATIONS = 10;

public static void run(Class<?> benchmarkClass) {
runAndReport(benchmarkClass, WARMUP_ITERATIONS, MEASUREMENT_ITERATIONS, Assertions.Disable);
}

public static void devRun(Class<?> benchmarkClass) {
runAndReport(benchmarkClass, QUICK_WARMUP_ITERATIONS, QUICK_MEASUREMENT_ITERATIONS, Assertions.Disable);
}

public static void devRunWithAssertions(Class<?> benchmarkClass) {
runAndReport(benchmarkClass, QUICK_WARMUP_ITERATIONS, QUICK_MEASUREMENT_ITERATIONS, Assertions.Enable);
}

private static void runAndReport(Class<?> benchmarkClass, int warmupIterations, int measurementIterations, Assertions assertions) {
Collection<RunResult> results = run(benchmarkClass, warmupIterations, measurementIterations, assertions);
BenchmarkPerformanceReporter.of(results).print();
}

private static Collection<RunResult> run(Class<?> benchmarkClass, int warmupIterations, int measurementIterations, Assertions assertions) {
final Options opts = new OptionsBuilder()
.include(benchmarkClass.getSimpleName())
.shouldDoGC(true)
.shouldFailOnError(true)
.mode(Mode.Throughput)
.timeUnit(TimeUnit.SECONDS)
.warmupTime(TimeValue.milliseconds(500))
.warmupIterations(warmupIterations)
.measurementTime(TimeValue.milliseconds(500))
.measurementIterations(measurementIterations)
.forks(1)
// We are using 4Gb and setting NewGen to 100% to avoid GC during testing.
// Any GC during testing will destroy the iteration, which should get ignored as an outlier
.jvmArgsAppend("-XX:+UseG1GC", "-Xss100m", "-Xms4g", "-Xmx4g", "-XX:+PrintGC", "-XX:MaxGCPauseMillis=1000", "-XX:+UnlockExperimentalVMOptions", "-XX:G1NewSizePercent=100", "-XX:G1MaxNewSizePercent=100", assertions.vmArg)
.build();

try {
return new Runner(opts).run();
}
catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}

private static enum Assertions {
Enable("-enableassertions"),
Disable("-disableassertions")
;

final String vmArg;
Assertions(String vmArg) {
this.vmArg = vmArg;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
package javaslang.benchmark;
package javaslang.benchmark.collection;

import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.results.RunResult;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.*;
import javaslang.benchmark.JmhRunner;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;

import java.util.*;
import java.util.concurrent.TimeUnit;

import static javaslang.benchmark.BenchmarkResultAggregator.displayRatios;
import java.util.Objects;
import java.util.Random;

public class ArrayBenchmark {
public static void main(String... args) throws Exception { /* main is more reliable than a test */
final Options opts = new OptionsBuilder()
.include(ArrayBenchmark.class.getSimpleName())
.shouldDoGC(false)
.shouldFailOnError(true)
.build();

final Collection<RunResult> results = new Runner(opts).run();
displayRatios(results, "^.*slang.*$");

public static void main(String... args) { /* main is more reliable than a test */
JmhRunner.run(ArrayBenchmark.class);
}

@State(Scope.Benchmark)
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.SECONDS)
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 2, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(value = 1, jvmArgsAppend = { "-XX:+UseG1GC", "-Xss100m", "-Xms1g", "-Xmx1g", "-disableassertions" }) /* set fork to 0 if you want to debug */
public static class Base {
@Param({ "10", "100", "1000" })
@Param({ "10", "100", "1000", "10000"})
public int CONTAINER_SIZE;

public Integer[] ELEMENTS;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,28 @@
package javaslang.benchmark;
package javaslang.benchmark.collection;

import javaslang.benchmark.JmhRunner;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.results.RunResult;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Objects;
import java.util.Random;
import java.util.concurrent.TimeUnit;

public class ListBenchmark {
public static void main(String... args) throws Exception { /* main is more reliable than a test */
final Options opts = new OptionsBuilder()
.include(ListBenchmark.class.getSimpleName())
.shouldDoGC(true)
.shouldFailOnError(true)
.build();

final Collection<RunResult> results = new Runner(opts).run();
BenchmarkPerformanceReporter.of(results).print();

public static void main(String... args) { /* main is more reliable than a test */
JmhRunner.run(ListBenchmark.class);
}

@State(Scope.Benchmark)
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.SECONDS)
@Warmup(iterations = 10, time = 500, timeUnit = TimeUnit.MILLISECONDS)
@Measurement(iterations = 40, time = 500, timeUnit = TimeUnit.MILLISECONDS)
@Fork(value = 1, jvmArgsAppend = { "-XX:+UseG1GC", "-Xss100m", "-Xms1g", "-Xmx1g", "-disableassertions" }) /* set fork to 0 if you want to debug */
public static class Base {
@Param({ "10", "100", "1000", "10000" })
@Param({ "10", "100", "1000", "10000"})
public int CONTAINER_SIZE;

public Integer[] ELEMENTS;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,44 +1,37 @@
package javaslang.benchmark;
package javaslang.benchmark.collection;

import javaslang.Tuple2;
import javaslang.benchmark.JmhRunner;
import javaslang.collection.Traversable;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.results.RunResult;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.options.*;
import org.openjdk.jmh.annotations.TearDown;
import scala.math.Ordering;
import scala.math.Ordering$;
import scalaz.*;
import scalaz.Heap;
import scalaz.Order;
import scalaz.Order$;

import java.util.*;
import java.util.concurrent.TimeUnit;

import static javaslang.benchmark.BenchmarkResultAggregator.displayRatios;
import java.util.Collections;
import java.util.Objects;
import java.util.Random;

public class PriorityQueueBenchmark {
public static void main(String... args) throws Exception { /* main is more reliable than a test */
final Options opts = new OptionsBuilder()
.include(PriorityQueueBenchmark.class.getSimpleName())
.shouldDoGC(false)
.shouldFailOnError(true)
.build();

final Collection<RunResult> results = new Runner(opts).run();
displayRatios(results, "^.*slang.*$");

public static void main(String... args) { /* main is more reliable than a test */
JmhRunner.run(PriorityQueueBenchmark.class);
}

@State(Scope.Benchmark)
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.SECONDS)
@Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(value = 1, jvmArgsAppend = { "-XX:+UseG1GC", "-Xss100m", "-Xms1g", "-Xmx1g", "-disableassertions" }) /* set fork to 0 if you want to debug */
public static class Base {
protected static final Ordering<Integer> SCALA_ORDERING = Ordering$.MODULE$.comparatorToOrdering(Integer::compareTo);
protected static final Order<Integer> SCALAZ_ORDER = Order$.MODULE$.fromScalaOrdering(SCALA_ORDERING);

@Param({ "10", "1000", "100000" })
@Param({ "10", "100", "1000", "10000"})
public int CONTAINER_SIZE;

public Integer[] ELEMENTS;
Expand Down

0 comments on commit d674941

Please sign in to comment.