-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #881 from benjchristensen/lift-performance
Lift Performance
- Loading branch information
Showing
3 changed files
with
74 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
rxjava-core/src/perf/java/rx/composition/RangeMapTakeOnNextPerf.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package rx.composition; | ||
|
||
import rx.Observable; | ||
import rx.perf.AbstractPerformanceTester; | ||
import rx.perf.IntegerSumObserver; | ||
import rx.util.functions.Action0; | ||
import rx.util.functions.Func1; | ||
|
||
public class RangeMapTakeOnNextPerf extends AbstractPerformanceTester { | ||
|
||
final static int NUM = 10; | ||
final static long REPS = REPETITIONS / NUM; | ||
|
||
RangeMapTakeOnNextPerf() { | ||
super(REPS); | ||
} | ||
|
||
public static void main(String args[]) { | ||
|
||
final RangeMapTakeOnNextPerf spt = new RangeMapTakeOnNextPerf(); | ||
try { | ||
spt.runTest(new Action0() { | ||
|
||
@Override | ||
public void call() { | ||
spt.test(); | ||
} | ||
}); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
/** | ||
* | ||
* With 'lift' calling the `f` function directly: | ||
* | ||
* Run: 10 - 11,152,996 ops/sec | ||
* Run: 11 - 9,791,825 ops/sec | ||
* Run: 12 - 10,080,035 ops/sec | ||
* Run: 13 - 10,189,525 ops/sec | ||
* Run: 14 - 10,145,486 ops/sec | ||
* | ||
* With `lift` calling `subscribe`: | ||
* | ||
* Run: 10 - 5,592,153 ops/sec | ||
* Run: 11 - 5,881,799 ops/sec | ||
* Run: 12 - 5,853,430 ops/sec | ||
* Run: 13 - 5,902,769 ops/sec | ||
* Run: 14 - 5,907,721 ops/sec | ||
*/ | ||
public long test() { | ||
|
||
Observable<Integer> s = Observable.range(0, 100).map(new Func1<Integer, Integer>() { | ||
|
||
@Override | ||
public Integer call(Integer l) { | ||
return l + 1; | ||
} | ||
|
||
}).take(NUM); | ||
IntegerSumObserver o = new IntegerSumObserver(); | ||
|
||
for (long l = 0; l < REPS; l++) { | ||
s.subscribe(o); | ||
} | ||
return o.sum; | ||
} | ||
|
||
} |