Skip to content

Instantly share code, notes, and snippets.

@minborg
Created October 8, 2018 10:45
Show Gist options
  • Save minborg/413472b59d68c897778ef7b602937fc0 to your computer and use it in GitHub Desktop.
Save minborg/413472b59d68c897778ef7b602937fc0 to your computer and use it in GitHub Desktop.
package com.example;
import com.speedment.common.singletonstream.SingletonStream;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import java.util.function.Consumer;
import java.util.stream.Stream;
@State(Scope.Benchmark)
public class SingletonBench {
@Benchmark
public long singletonStreamCount() {
return
SingletonStream.of("A").count();
}
@Benchmark
public long streamCount() {
return
Stream.of("A").count();
}
@Benchmark
public void singletonStreamForEach() {
SingletonStream.of("A")
.limit(1)
.forEach(blackHole());
}
@Benchmark
public void streamForEach() {
Stream.of("A")
.limit(1)
.forEach(blackHole());
}
private static <T> Consumer<T> blackHole() {
return t -> {};
}
public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(SingletonBench.class.getSimpleName())
.mode(Mode.Throughput) // Mode.Throughput
.threads(1) // Threads.MAX
.forks(1)
.warmupIterations(1)
.measurementIterations(1)
.build();
new Runner(opt).run();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment