Skip to content

Commit e657d22

Browse files
Performance Testing
1 parent 10e8b78 commit e657d22

9 files changed

+88
-8
lines changed

rxjava-core/src/perf/java/rx/ObservableCreatePerformance.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
public class ObservableCreatePerformance extends AbstractPerformanceTester {
99

10+
ObservableCreatePerformance() {
11+
super(REPETITIONS);
12+
}
13+
1014
public static void main(String args[]) {
1115

1216
final ObservableCreatePerformance spt = new ObservableCreatePerformance();

rxjava-core/src/perf/java/rx/operators/OperatorFromIterablePerformance.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
public class OperatorFromIterablePerformance extends AbstractPerformanceTester {
1313

14+
OperatorFromIterablePerformance() {
15+
super(REPETITIONS);
16+
}
17+
1418
public static void main(String args[]) {
1519

1620
final OperatorFromIterablePerformance spt = new OperatorFromIterablePerformance();

rxjava-core/src/perf/java/rx/operators/OperatorMapPerformance.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
public class OperatorMapPerformance extends AbstractPerformanceTester {
1010

11+
OperatorMapPerformance() {
12+
super(REPETITIONS);
13+
}
14+
1115
public static void main(String args[]) {
1216

1317
final OperatorMapPerformance spt = new OperatorMapPerformance();

rxjava-core/src/perf/java/rx/operators/OperatorMergePerformance.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99

1010
public class OperatorMergePerformance extends AbstractPerformanceTester {
1111

12+
OperatorMergePerformance() {
13+
super(REPETITIONS);
14+
}
15+
1216
public static void main(String args[]) {
1317

1418
final OperatorMergePerformance spt = new OperatorMergePerformance();
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package rx.operators;
2+
3+
import rx.Observable;
4+
import rx.perf.AbstractPerformanceTester;
5+
import rx.perf.IntegerSumObserver;
6+
import rx.schedulers.Schedulers;
7+
import rx.util.functions.Action0;
8+
9+
public class OperatorObserveOnPerformance extends AbstractPerformanceTester {
10+
11+
private static long reps = 1000000;
12+
13+
OperatorObserveOnPerformance() {
14+
super(reps);
15+
}
16+
17+
public static void main(String args[]) {
18+
19+
final OperatorObserveOnPerformance spt = new OperatorObserveOnPerformance();
20+
try {
21+
spt.runTest(new Action0() {
22+
23+
@Override
24+
public void call() {
25+
spt.timeObserveOn();
26+
}
27+
});
28+
} catch (Exception e) {
29+
e.printStackTrace();
30+
}
31+
32+
}
33+
34+
/**
35+
* Observable.from(1L).observeOn()
36+
*
37+
*/
38+
public long timeObserveOn() {
39+
40+
Observable<Integer> s = Observable.range(1, (int) reps).observeOn(Schedulers.newThread());
41+
IntegerSumObserver o = new IntegerSumObserver();
42+
s.subscribe(o);
43+
return o.sum;
44+
}
45+
46+
}

rxjava-core/src/perf/java/rx/operators/OperatorTakePerformance.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
public class OperatorTakePerformance extends AbstractPerformanceTester {
99

10+
OperatorTakePerformance() {
11+
super(REPETITIONS);
12+
}
13+
1014
public static void main(String args[]) {
1115

1216
final OperatorTakePerformance spt = new OperatorTakePerformance();

rxjava-core/src/perf/java/rx/operators/OperatorZipPerformance.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
import rx.Observable;
44
import rx.perf.AbstractPerformanceTester;
55
import rx.perf.IntegerSumObserver;
6-
import rx.perf.LongSumObserver;
76
import rx.util.functions.Action0;
87
import rx.util.functions.Func2;
98

109
public class OperatorZipPerformance extends AbstractPerformanceTester {
1110

11+
OperatorZipPerformance() {
12+
super(REPETITIONS);
13+
}
14+
1215
public static void main(String args[]) {
1316

1417
final OperatorZipPerformance spt = new OperatorZipPerformance();

rxjava-core/src/perf/java/rx/perf/AbstractPerformanceTester.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@
66

77
public abstract class AbstractPerformanceTester {
88

9-
public static final int REPETITIONS = 5 * 1000 * 1000;
9+
public static final long REPETITIONS = 5 * 1000 * 1000;
1010
public static final int NUM_PRODUCERS = 1;
1111

12+
private final long repetitions;
13+
14+
protected AbstractPerformanceTester(long repetitions) {
15+
this.repetitions = repetitions;
16+
}
17+
1218
public final void runTest(Action0 action) throws InterruptedException {
1319
for (int runNum = 0; runNum < 15; runNum++) {
1420
System.gc();
@@ -19,7 +25,7 @@ public final void runTest(Action0 action) throws InterruptedException {
1925
action.call();
2026

2127
long duration = System.nanoTime() - start;
22-
long opsPerSec = (REPETITIONS * NUM_PRODUCERS * 1000L * 1000L * 1000L) / duration;
28+
long opsPerSec = (repetitions * NUM_PRODUCERS * 1000L * 1000L * 1000L) / duration;
2329
System.out.printf("Run: %d - %,d ops/sec \n",
2430
Integer.valueOf(runNum),
2531
Long.valueOf(opsPerSec));
@@ -39,14 +45,14 @@ public final void runTest(Action0 action) throws InterruptedException {
3945
*/
4046
public long baseline() {
4147
LongSumObserver o = new LongSumObserver();
42-
for (long l = 0; l < REPETITIONS; l++) {
48+
for (long l = 0; l < repetitions; l++) {
4349
o.onNext(l);
4450
}
4551
o.onCompleted();
4652
return o.sum;
4753
}
48-
49-
public static Iterable<Long> ITERABLE_OF_REPETITIONS = new Iterable<Long>() {
54+
55+
public Iterable<Long> ITERABLE_OF_REPETITIONS = new Iterable<Long>() {
5056

5157
@Override
5258
public Iterator<Long> iterator() {
@@ -55,7 +61,7 @@ public Iterator<Long> iterator() {
5561

5662
@Override
5763
public boolean hasNext() {
58-
return count <= REPETITIONS;
64+
return count <= repetitions;
5965
}
6066

6167
@Override
@@ -71,5 +77,5 @@ public void remove() {
7177
};
7278
};
7379
};
74-
80+
7581
}

rxjava-core/src/perf/java/rx/subscriptions/CompositeSubscriptionAddRemovePerf.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
import rx.util.functions.Action0;
55

66
public class CompositeSubscriptionAddRemovePerf extends AbstractPerformanceTester {
7+
8+
CompositeSubscriptionAddRemovePerf() {
9+
super(REPETITIONS);
10+
}
11+
712
public static void main(String[] args) {
813
final CompositeSubscriptionAddRemovePerf spt = new CompositeSubscriptionAddRemovePerf();
914
try {

0 commit comments

Comments
 (0)