|
1 | | -package rx.subscriptions; |
2 | | - |
3 | | -import rx.perf.AbstractPerformanceTester; |
4 | | -import rx.util.functions.Action0; |
5 | | - |
6 | | -public class CompositeSubscriptionAddRemovePerf extends AbstractPerformanceTester { |
7 | | - public static void main(String[] args) { |
8 | | - final CompositeSubscriptionAddRemovePerf spt = new CompositeSubscriptionAddRemovePerf(); |
9 | | - try { |
10 | | - spt.runTest(new Action0() { |
11 | | - @Override |
12 | | - public void call() { |
13 | | - spt.timeAddAndRemove(); |
14 | | - } |
15 | | - }); |
16 | | - } catch (Exception e) { |
17 | | - e.printStackTrace(); |
18 | | - } |
19 | | - } |
20 | | - |
21 | | - /** |
22 | | - * Test simple add + remove on a composite. |
23 | | - * |
24 | | - * With old Composite add/remove: |
25 | | - * |
26 | | - * Run: 10 - 14,985,141 ops/sec |
27 | | - * Run: 11 - 15,257,104 ops/sec |
28 | | - * Run: 12 - 14,797,996 ops/sec |
29 | | - * Run: 13 - 14,438,643 ops/sec |
30 | | - * Run: 14 - 14,985,864 ops/sec |
31 | | - * |
32 | | - * With optimized Composite add/remove: |
33 | | - * |
34 | | - * Run: 10 - 19,802,782 ops/sec |
35 | | - * Run: 11 - 18,896,021 ops/sec |
36 | | - * Run: 12 - 18,829,296 ops/sec |
37 | | - * Run: 13 - 19,729,876 ops/sec |
38 | | - * Run: 14 - 19,830,678 ops/sec |
39 | | - * |
40 | | - * about 32% increase |
41 | | - */ |
42 | | - void timeAddAndRemove() { |
43 | | - CompositeSubscription csub = new CompositeSubscription(); |
44 | | - BooleanSubscription bs = new BooleanSubscription(); |
45 | | - for (int i = 0; i < REPETITIONS; i++) { |
46 | | - csub.add(bs); |
47 | | - csub.remove(bs); |
48 | | - } |
49 | | - } |
50 | | -} |
| 1 | +package rx.subscriptions; |
| 2 | + |
| 3 | +import rx.perf.AbstractPerformanceTester; |
| 4 | +import rx.util.functions.Action0; |
| 5 | + |
| 6 | +public class CompositeSubscriptionAddRemovePerf extends AbstractPerformanceTester { |
| 7 | + public static void main(String[] args) { |
| 8 | + final CompositeSubscriptionAddRemovePerf spt = new CompositeSubscriptionAddRemovePerf(); |
| 9 | + try { |
| 10 | + spt.runTest(new Action0() { |
| 11 | + @Override |
| 12 | + public void call() { |
| 13 | + spt.timeAddAndRemove(); |
| 14 | + } |
| 15 | + }); |
| 16 | + } catch (Exception e) { |
| 17 | + e.printStackTrace(); |
| 18 | + } |
| 19 | + } |
| 20 | + |
| 21 | + /** |
| 22 | + * Test simple add + remove on a composite. |
| 23 | + * |
| 24 | + * With old Composite add/remove: |
| 25 | + * |
| 26 | + * Run: 10 - 14,985,141 ops/sec |
| 27 | + * Run: 11 - 15,257,104 ops/sec |
| 28 | + * Run: 12 - 14,797,996 ops/sec |
| 29 | + * Run: 13 - 14,438,643 ops/sec |
| 30 | + * Run: 14 - 14,985,864 ops/sec |
| 31 | + * |
| 32 | + * With optimized Composite add/remove: |
| 33 | + * |
| 34 | + * Run: 10 - 19,802,782 ops/sec |
| 35 | + * Run: 11 - 18,896,021 ops/sec |
| 36 | + * Run: 12 - 18,829,296 ops/sec |
| 37 | + * Run: 13 - 19,729,876 ops/sec |
| 38 | + * Run: 14 - 19,830,678 ops/sec |
| 39 | + * |
| 40 | + * about 32% increase |
| 41 | + */ |
| 42 | + void timeAddAndRemove() { |
| 43 | + CompositeSubscription csub = new CompositeSubscription(); |
| 44 | + BooleanSubscription bs = new BooleanSubscription(); |
| 45 | + for (int i = 0; i < REPETITIONS; i++) { |
| 46 | + csub.add(bs); |
| 47 | + csub.remove(bs); |
| 48 | + } |
| 49 | + } |
| 50 | +} |
0 commit comments