Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.