Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Baseline Performance Tests #1350

Merged
merged 1 commit into from
Jun 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions rxjava-core/src/perf/java/rx/usecases/PerfBaseline.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package rx.usecases;

import java.util.Iterator;

import org.openjdk.jmh.annotations.GenerateMicroBenchmark;

public class PerfBaseline {

@GenerateMicroBenchmark
public void forLoopConsumption(UseCaseInput input) throws InterruptedException {
for (int i = 0; i < input.size; i++) {
input.observer.onNext(i);
}
}

@GenerateMicroBenchmark
public void observableConsumption(UseCaseInput input) throws InterruptedException {
input.observable.subscribe(input.observer);
input.awaitCompletion();
}

@GenerateMicroBenchmark
public void iterableViaForLoopConsumption(UseCaseInput input) throws InterruptedException {
for (int i : input.iterable) {
input.observer.onNext(i);
}
}

@GenerateMicroBenchmark
public void iterableViaHasNextConsumption(UseCaseInput input) throws InterruptedException {
Iterator<Integer> iterator = input.iterable.iterator();
while (iterator.hasNext()) {
input.observer.onNext(iterator.next());
}
}
}
14 changes: 13 additions & 1 deletion rxjava-core/src/perf/java/rx/usecases/PerfObserveOn.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,21 @@
public class PerfObserveOn {

@GenerateMicroBenchmark
public void observeOn(UseCaseInput input) throws InterruptedException {
public void observeOnComputation(UseCaseInput input) throws InterruptedException {
input.observable.observeOn(Schedulers.computation()).subscribe(input.observer);
input.awaitCompletion();
}

@GenerateMicroBenchmark
public void observeOnNewThread(UseCaseInput input) throws InterruptedException {
input.observable.observeOn(Schedulers.newThread()).subscribe(input.observer);
input.awaitCompletion();
}

@GenerateMicroBenchmark
public void observeOnImmediate(UseCaseInput input) throws InterruptedException {
input.observable.observeOn(Schedulers.immediate()).subscribe(input.observer);
input.awaitCompletion();
}

}
18 changes: 15 additions & 3 deletions rxjava-core/src/perf/java/rx/usecases/PerfTransforms.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,24 @@

import rx.Observable;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

public class PerfTransforms {

@GenerateMicroBenchmark
public void mapTransformation(UseCaseInput input) throws InterruptedException {
public void mapPassThru(UseCaseInput input) throws InterruptedException {
input.observable.map(new Func1<Integer, Integer>() {

@Override
public Integer call(Integer i) {
return i;
}

}).subscribe(input.observer);
input.awaitCompletion();
}

@GenerateMicroBenchmark
public void mapIntStringInt(UseCaseInput input) throws InterruptedException {
input.observable.map(new Func1<Integer, String>() {

@Override
Expand All @@ -44,7 +56,7 @@ public Integer call(String i) {
}

@GenerateMicroBenchmark
public void flatMapTransforms(UseCaseInput input) throws InterruptedException {
public void flatMapInt(UseCaseInput input) throws InterruptedException {
input.observable.flatMap(new Func1<Integer, Observable<Integer>>() {

@Override
Expand Down
30 changes: 30 additions & 0 deletions rxjava-core/src/perf/java/rx/usecases/UseCaseInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package rx.usecases;

import java.util.Iterator;
import java.util.concurrent.CountDownLatch;

import org.openjdk.jmh.annotations.Param;
Expand All @@ -36,6 +37,7 @@ public class UseCaseInput {
@Param({ "1", "1024" })
public int size;

public Iterable<Integer> iterable;
public Observable<Integer> observable;
public Observer<Integer> observer;

Expand All @@ -52,6 +54,34 @@ public void call(Subscriber<? super Integer> o) {
o.onCompleted();
}
});

iterable = new Iterable<Integer>() {

@Override
public Iterator<Integer> iterator() {
return new Iterator<Integer>() {

int i=0;

@Override
public boolean hasNext() {
return i < size;
}

@Override
public Integer next() {
return i++;
}

@Override
public void remove() {

}

};
}

};

latch = new CountDownLatch(1);

Expand Down