diff --git a/rxjava-core/src/perf/java/rx/ObservableCreatePerformance.java b/rxjava-core/src/perf/java/rx/ObservableCreatePerformance.java index f55dd998bd..6e892a324b 100644 --- a/rxjava-core/src/perf/java/rx/ObservableCreatePerformance.java +++ b/rxjava-core/src/perf/java/rx/ObservableCreatePerformance.java @@ -7,6 +7,10 @@ public class ObservableCreatePerformance extends AbstractPerformanceTester { + ObservableCreatePerformance() { + super(REPETITIONS); + } + public static void main(String args[]) { final ObservableCreatePerformance spt = new ObservableCreatePerformance(); diff --git a/rxjava-core/src/perf/java/rx/operators/OperatorFromIterablePerformance.java b/rxjava-core/src/perf/java/rx/operators/OperatorFromIterablePerformance.java index acb41eb576..ea3f2c18c3 100644 --- a/rxjava-core/src/perf/java/rx/operators/OperatorFromIterablePerformance.java +++ b/rxjava-core/src/perf/java/rx/operators/OperatorFromIterablePerformance.java @@ -11,6 +11,10 @@ public class OperatorFromIterablePerformance extends AbstractPerformanceTester { + OperatorFromIterablePerformance() { + super(REPETITIONS); + } + public static void main(String args[]) { final OperatorFromIterablePerformance spt = new OperatorFromIterablePerformance(); diff --git a/rxjava-core/src/perf/java/rx/operators/OperatorMapPerformance.java b/rxjava-core/src/perf/java/rx/operators/OperatorMapPerformance.java index 2f73af1d0e..dc85a1d6e6 100644 --- a/rxjava-core/src/perf/java/rx/operators/OperatorMapPerformance.java +++ b/rxjava-core/src/perf/java/rx/operators/OperatorMapPerformance.java @@ -8,6 +8,10 @@ public class OperatorMapPerformance extends AbstractPerformanceTester { + OperatorMapPerformance() { + super(REPETITIONS); + } + public static void main(String args[]) { final OperatorMapPerformance spt = new OperatorMapPerformance(); diff --git a/rxjava-core/src/perf/java/rx/operators/OperatorMergePerformance.java b/rxjava-core/src/perf/java/rx/operators/OperatorMergePerformance.java index de4b204ff1..99ce4deac9 100644 --- a/rxjava-core/src/perf/java/rx/operators/OperatorMergePerformance.java +++ b/rxjava-core/src/perf/java/rx/operators/OperatorMergePerformance.java @@ -9,6 +9,10 @@ public class OperatorMergePerformance extends AbstractPerformanceTester { + OperatorMergePerformance() { + super(REPETITIONS); + } + public static void main(String args[]) { final OperatorMergePerformance spt = new OperatorMergePerformance(); diff --git a/rxjava-core/src/perf/java/rx/operators/OperatorObserveOnPerformance.java b/rxjava-core/src/perf/java/rx/operators/OperatorObserveOnPerformance.java new file mode 100644 index 0000000000..c25857ea54 --- /dev/null +++ b/rxjava-core/src/perf/java/rx/operators/OperatorObserveOnPerformance.java @@ -0,0 +1,46 @@ +package rx.operators; + +import rx.Observable; +import rx.perf.AbstractPerformanceTester; +import rx.perf.IntegerSumObserver; +import rx.schedulers.Schedulers; +import rx.util.functions.Action0; + +public class OperatorObserveOnPerformance extends AbstractPerformanceTester { + + private static long reps = 1000000; + + OperatorObserveOnPerformance() { + super(reps); + } + + public static void main(String args[]) { + + final OperatorObserveOnPerformance spt = new OperatorObserveOnPerformance(); + try { + spt.runTest(new Action0() { + + @Override + public void call() { + spt.timeObserveOn(); + } + }); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + /** + * Observable.from(1L).observeOn() + * + */ + public long timeObserveOn() { + + Observable s = Observable.range(1, (int) reps).observeOn(Schedulers.newThread()); + IntegerSumObserver o = new IntegerSumObserver(); + s.subscribe(o); + return o.sum; + } + +} \ No newline at end of file diff --git a/rxjava-core/src/perf/java/rx/operators/OperatorTakePerformance.java b/rxjava-core/src/perf/java/rx/operators/OperatorTakePerformance.java index b64b3c9de1..3e8e8be702 100644 --- a/rxjava-core/src/perf/java/rx/operators/OperatorTakePerformance.java +++ b/rxjava-core/src/perf/java/rx/operators/OperatorTakePerformance.java @@ -7,6 +7,10 @@ public class OperatorTakePerformance extends AbstractPerformanceTester { + OperatorTakePerformance() { + super(REPETITIONS); + } + public static void main(String args[]) { final OperatorTakePerformance spt = new OperatorTakePerformance(); diff --git a/rxjava-core/src/perf/java/rx/operators/OperatorZipPerformance.java b/rxjava-core/src/perf/java/rx/operators/OperatorZipPerformance.java index 2f22b81303..0d929b6a33 100644 --- a/rxjava-core/src/perf/java/rx/operators/OperatorZipPerformance.java +++ b/rxjava-core/src/perf/java/rx/operators/OperatorZipPerformance.java @@ -3,12 +3,15 @@ import rx.Observable; import rx.perf.AbstractPerformanceTester; import rx.perf.IntegerSumObserver; -import rx.perf.LongSumObserver; import rx.util.functions.Action0; import rx.util.functions.Func2; public class OperatorZipPerformance extends AbstractPerformanceTester { + OperatorZipPerformance() { + super(REPETITIONS); + } + public static void main(String args[]) { final OperatorZipPerformance spt = new OperatorZipPerformance(); diff --git a/rxjava-core/src/perf/java/rx/perf/AbstractPerformanceTester.java b/rxjava-core/src/perf/java/rx/perf/AbstractPerformanceTester.java index 56d92278ab..468f900f88 100644 --- a/rxjava-core/src/perf/java/rx/perf/AbstractPerformanceTester.java +++ b/rxjava-core/src/perf/java/rx/perf/AbstractPerformanceTester.java @@ -6,9 +6,15 @@ public abstract class AbstractPerformanceTester { - public static final int REPETITIONS = 5 * 1000 * 1000; + public static final long REPETITIONS = 5 * 1000 * 1000; public static final int NUM_PRODUCERS = 1; + private final long repetitions; + + protected AbstractPerformanceTester(long repetitions) { + this.repetitions = repetitions; + } + public final void runTest(Action0 action) throws InterruptedException { for (int runNum = 0; runNum < 15; runNum++) { System.gc(); @@ -19,7 +25,7 @@ public final void runTest(Action0 action) throws InterruptedException { action.call(); long duration = System.nanoTime() - start; - long opsPerSec = (REPETITIONS * NUM_PRODUCERS * 1000L * 1000L * 1000L) / duration; + long opsPerSec = (repetitions * NUM_PRODUCERS * 1000L * 1000L * 1000L) / duration; System.out.printf("Run: %d - %,d ops/sec \n", Integer.valueOf(runNum), Long.valueOf(opsPerSec)); @@ -39,14 +45,14 @@ public final void runTest(Action0 action) throws InterruptedException { */ public long baseline() { LongSumObserver o = new LongSumObserver(); - for (long l = 0; l < REPETITIONS; l++) { + for (long l = 0; l < repetitions; l++) { o.onNext(l); } o.onCompleted(); return o.sum; } - - public static Iterable ITERABLE_OF_REPETITIONS = new Iterable() { + + public Iterable ITERABLE_OF_REPETITIONS = new Iterable() { @Override public Iterator iterator() { @@ -55,7 +61,7 @@ public Iterator iterator() { @Override public boolean hasNext() { - return count <= REPETITIONS; + return count <= repetitions; } @Override @@ -71,5 +77,5 @@ public void remove() { }; }; }; - + } diff --git a/rxjava-core/src/perf/java/rx/subscriptions/CompositeSubscriptionAddRemovePerf.java b/rxjava-core/src/perf/java/rx/subscriptions/CompositeSubscriptionAddRemovePerf.java index b582e9edd0..487f34b558 100644 --- a/rxjava-core/src/perf/java/rx/subscriptions/CompositeSubscriptionAddRemovePerf.java +++ b/rxjava-core/src/perf/java/rx/subscriptions/CompositeSubscriptionAddRemovePerf.java @@ -4,6 +4,11 @@ import rx.util.functions.Action0; public class CompositeSubscriptionAddRemovePerf extends AbstractPerformanceTester { + + CompositeSubscriptionAddRemovePerf() { + super(REPETITIONS); + } + public static void main(String[] args) { final CompositeSubscriptionAddRemovePerf spt = new CompositeSubscriptionAddRemovePerf(); try {