package com.github.davidmoten.rx;

import org.openjdk.jmh.annotations.Benchmark;

import rx.Observable;
import rx.functions.Func2;

import com.github.davidmoten.rx.operators.OperatorReduce;

public class Benchmarks {

    @Benchmark
    public void reduceManyFromRxJavaLibrary() {
        Observable.range(1, 1000000).reduce(0, COUNT).subscribe();
    }

    @Benchmark
    public void reduceManyFromExtras() {
        Observable.range(1, 1000000).lift(OperatorReduce.create(0, COUNT)).subscribe();
    }

    @Benchmark
    public void reduceFewFromRxJavaLibrary() {
        Observable.range(1, 5).reduce(0, COUNT).subscribe();
    }

    @Benchmark
    public void reduceFewFromExtras() {
        Observable.range(1, 5).lift(OperatorReduce.create(0, COUNT)).subscribe();
    }

    private static final Func2<Integer, ? super Integer, Integer> COUNT = new Func2<Integer, Integer, Integer>() {

        @Override
        public Integer call(Integer count, Integer o) {
            return count + 1;
        }
    };
}

@@ -123,16 +123,49 @@
 s.Func2;
+%0Aimport rx.schedulers.Schedulers;
 %0A%0Aimport
@@ -524,32 +524,460 @@
 cribe();%0A    %7D%0A%0A
+    @Benchmark%0A    public void reduceManyFromRxJavaLibraryAsync() %7B%0A        Observable.range(1, 1000000).reduce(0, COUNT).subscribeOn(Schedulers.computation())%0A                .toBlocking().single();%0A    %7D%0A%0A    @Benchmark%0A    public void reduceManyFromExtrasAsync() %7B%0A        Observable.range(1, 1000000).lift(OperatorReduce.create(0, COUNT))%0A                .subscribeOn(Schedulers.computation()).toBlocking().single();%0A    %7D%0A%0A
     @Benchmark%0A 

add benchmarks