Skip to content

Commit

Permalink
Performance Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
benjchristensen committed Feb 8, 2014
1 parent 10e8b78 commit e657d22
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 8 deletions.
4 changes: 4 additions & 0 deletions rxjava-core/src/perf/java/rx/ObservableCreatePerformance.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

public class ObservableCreatePerformance extends AbstractPerformanceTester {

ObservableCreatePerformance() {
super(REPETITIONS);
}

public static void main(String args[]) {

final ObservableCreatePerformance spt = new ObservableCreatePerformance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

public class OperatorFromIterablePerformance extends AbstractPerformanceTester {

OperatorFromIterablePerformance() {
super(REPETITIONS);
}

public static void main(String args[]) {

final OperatorFromIterablePerformance spt = new OperatorFromIterablePerformance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

public class OperatorMapPerformance extends AbstractPerformanceTester {

OperatorMapPerformance() {
super(REPETITIONS);
}

public static void main(String args[]) {

final OperatorMapPerformance spt = new OperatorMapPerformance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

public class OperatorMergePerformance extends AbstractPerformanceTester {

OperatorMergePerformance() {
super(REPETITIONS);
}

public static void main(String args[]) {

final OperatorMergePerformance spt = new OperatorMergePerformance();
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Integer> s = Observable.range(1, (int) reps).observeOn(Schedulers.newThread());
IntegerSumObserver o = new IntegerSumObserver();
s.subscribe(o);
return o.sum;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

public class OperatorTakePerformance extends AbstractPerformanceTester {

OperatorTakePerformance() {
super(REPETITIONS);
}

public static void main(String args[]) {

final OperatorTakePerformance spt = new OperatorTakePerformance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 13 additions & 7 deletions rxjava-core/src/perf/java/rx/perf/AbstractPerformanceTester.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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));
Expand All @@ -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<Long> ITERABLE_OF_REPETITIONS = new Iterable<Long>() {

public Iterable<Long> ITERABLE_OF_REPETITIONS = new Iterable<Long>() {

@Override
public Iterator<Long> iterator() {
Expand All @@ -55,7 +61,7 @@ public Iterator<Long> iterator() {

@Override
public boolean hasNext() {
return count <= REPETITIONS;
return count <= repetitions;
}

@Override
Expand All @@ -71,5 +77,5 @@ public void remove() {
};
};
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e657d22

Please sign in to comment.