Created
December 15, 2015 08:38
-
-
Save szarnekow/993793279e7b7abf913f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package qn.interned; | |
import cfg.Config; | |
import org.openjdk.jmh.annotations.*; | |
import org.openjdk.jmh.infra.Blackhole; | |
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.ArrayList; | |
import java.util.List; | |
@BenchmarkMode(Mode.Throughput) | |
@Warmup(iterations = Config.warmup) | |
@Measurement(iterations = Config.measurment) | |
@Fork(value = Config.forks, warmups = Config.forks) | |
public class QNBenchmark { | |
@State(Scope.Benchmark) | |
public static class BenchmarkState { | |
List<String> allStrings; | |
@Setup | |
public void setup() throws Exception { | |
allStrings = new ArrayList<>(); | |
for(int i = 0; i < 100000; i++) { | |
String segment = String.valueOf(i); | |
allStrings.add(segment); | |
} | |
} | |
} | |
@Benchmark | |
@OperationsPerInvocation(100000) | |
public void createManyInterned(BenchmarkState state, Blackhole bh) { | |
for(String s: state.allStrings) { | |
bh.consume(QualifiedName.create(s)); | |
} | |
} | |
@Benchmark | |
public QualifiedName createInterned(BenchmarkState state) { | |
return QualifiedName.create(state.allStrings); | |
} | |
@Benchmark | |
@OperationsPerInvocation(100000) | |
public void createMany(BenchmarkState state, Blackhole bh) { | |
for(String s: state.allStrings) { | |
bh.consume(qn.orig.QualifiedName.create(s)); | |
} | |
} | |
@Benchmark | |
public qn.orig.QualifiedName create(BenchmarkState state) { | |
return qn.orig.QualifiedName.create(state.allStrings); | |
} | |
public static void main(String[] args) throws RunnerException { | |
Options opt = new OptionsBuilder().include( | |
QNBenchmark.class.getSimpleName()).build(); | |
new Runner(opt).run(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment