Skip to content

2.x: perf change wait to spin-loop for short async benchmarks #3354

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

Merged
merged 1 commit into from
Sep 18, 2015
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
6 changes: 5 additions & 1 deletion src/perf/java/io/reactivex/OperatorFlatMapPerf.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ public void flatMapIntPassthruAsync(Input input) throws InterruptedException {
input.observable.flatMap(i -> {
return Observable.just(i).subscribeOn(Schedulers.computation());
}).subscribe(latchedObserver);
latchedObserver.latch.await();
if (input.size == 1) {
while (latchedObserver.latch.getCount() != 0);
} else {
latchedObserver.latch.await();
}
}

@Benchmark
Expand Down
38 changes: 32 additions & 6 deletions src/perf/java/io/reactivex/OperatorMergePerf.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ public void oneStreamOfNthatMergesIn1(final InputMillion input) throws Interrupt
Observable<Observable<Integer>> os = Observable.range(1, input.size).map(Observable::just);
LatchedObserver<Integer> o = input.newLatchedObserver();
Observable.merge(os).subscribe(o);
o.latch.await();

if (input.size == 1) {
while (o.latch.getCount() != 0);
} else {
o.latch.await();
}
}

// flatMap
Expand All @@ -42,7 +47,12 @@ public void merge1SyncStreamOfN(final InputMillion input) throws InterruptedExce
});
LatchedObserver<Integer> o = input.newLatchedObserver();
Observable.merge(os).subscribe(o);
o.latch.await();

if (input.size == 1) {
while (o.latch.getCount() != 0);
} else {
o.latch.await();
}
}

@Benchmark
Expand All @@ -52,7 +62,11 @@ public void mergeNSyncStreamsOfN(final InputThousand input) throws InterruptedEx
});
LatchedObserver<Integer> o = input.newLatchedObserver();
Observable.merge(os).subscribe(o);
o.latch.await();
if (input.size == 1) {
while (o.latch.getCount() != 0);
} else {
o.latch.await();
}
}

@Benchmark
Expand All @@ -62,22 +76,34 @@ public void mergeNAsyncStreamsOfN(final InputThousand input) throws InterruptedE
});
LatchedObserver<Integer> o = input.newLatchedObserver();
Observable.merge(os).subscribe(o);
o.latch.await();
if (input.size == 1) {
while (o.latch.getCount() != 0);
} else {
o.latch.await();
}
}

@Benchmark
public void mergeTwoAsyncStreamsOfN(final InputThousand input) throws InterruptedException {
LatchedObserver<Integer> o = input.newLatchedObserver();
Observable<Integer> ob = Observable.range(0, input.size).subscribeOn(Schedulers.computation());
Observable.merge(ob, ob).subscribe(o);
o.latch.await();
if (input.size == 1) {
while (o.latch.getCount() != 0);
} else {
o.latch.await();
}
}

@Benchmark
public void mergeNSyncStreamsOf1(final InputForMergeN input) throws InterruptedException {
LatchedObserver<Integer> o = input.newLatchedObserver();
Observable.merge(input.observables).subscribe(o);
o.latch.await();
if (input.size == 1) {
while (o.latch.getCount() != 0);
} else {
o.latch.await();
}
}

@State(Scope.Thread)
Expand Down
12 changes: 10 additions & 2 deletions src/perf/java/io/reactivex/RangePerf.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ public void rangeAsync(Blackhole bh) throws Exception {

rangeAsync.subscribe(lo);

lo.latch.await();
if (times == 1) {
while (lo.latch.getCount() != 0);
} else {
lo.latch.await();
}
}

@Benchmark
Expand All @@ -70,7 +74,11 @@ public void rangePipeline(Blackhole bh) throws Exception {

rangeAsyncPipeline.subscribe(lo);

lo.latch.await();
if (times == 1) {
while (lo.latch.getCount() != 0);
} else {
lo.latch.await();
}
}

}