|
| 1 | +package rx; |
| 2 | + |
| 3 | +import java.util.Iterator; |
| 4 | +import java.util.concurrent.TimeUnit; |
| 5 | + |
| 6 | +import org.openjdk.jmh.annotations.BenchmarkMode; |
| 7 | +import org.openjdk.jmh.annotations.GenerateMicroBenchmark; |
| 8 | +import org.openjdk.jmh.annotations.Mode; |
| 9 | +import org.openjdk.jmh.annotations.OutputTimeUnit; |
| 10 | +import org.openjdk.jmh.annotations.Param; |
| 11 | +import org.openjdk.jmh.annotations.Scope; |
| 12 | +import org.openjdk.jmh.annotations.State; |
| 13 | + |
| 14 | +import rx.jmh.InputWithIncrementingInteger; |
| 15 | + |
| 16 | +@BenchmarkMode(Mode.Throughput) |
| 17 | +@OutputTimeUnit(TimeUnit.SECONDS) |
| 18 | +public class PerfBaseline { |
| 19 | + |
| 20 | + @State(Scope.Thread) |
| 21 | + public static class Input extends InputWithIncrementingInteger { |
| 22 | + |
| 23 | + @Param({ "1", "1000", "1000000" }) |
| 24 | + public int size; |
| 25 | + |
| 26 | + @Override |
| 27 | + public int getSize() { |
| 28 | + return size; |
| 29 | + } |
| 30 | + |
| 31 | + } |
| 32 | + |
| 33 | + @GenerateMicroBenchmark |
| 34 | + public void observableConsumption(Input input) throws InterruptedException { |
| 35 | + input.firehose.subscribe(input.observer); |
| 36 | + } |
| 37 | + |
| 38 | + @GenerateMicroBenchmark |
| 39 | + public void observableViaRange(Input input) throws InterruptedException { |
| 40 | + input.observable.subscribe(input.observer); |
| 41 | + } |
| 42 | + |
| 43 | + @GenerateMicroBenchmark |
| 44 | + public void iterableViaForLoopConsumption(Input input) throws InterruptedException { |
| 45 | + for (int i : input.iterable) { |
| 46 | + input.observer.onNext(i); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + @GenerateMicroBenchmark |
| 51 | + public void iterableViaHasNextConsumption(Input input) throws InterruptedException { |
| 52 | + Iterator<Integer> iterator = input.iterable.iterator(); |
| 53 | + while (iterator.hasNext()) { |
| 54 | + input.observer.onNext(iterator.next()); |
| 55 | + } |
| 56 | + } |
| 57 | +} |
0 commit comments