proxygen
RxBenchmark.cpp File Reference
#include <folly/Benchmark.h>
#include <wangle/deprecated/rx/Observer.h>
#include <wangle/deprecated/rx/Subject.h>
#include <gflags/gflags.h>

Go to the source code of this file.

Functions

static std::unique_ptr< Observer< int > > makeObserver ()
 
void subscribeImpl (uint32_t iters, int N, bool countUnsubscribe)
 
void subscribeAndUnsubscribe (uint32_t iters, int N)
 
void subscribe (uint32_t iters, int N)
 
void observe (uint32_t iters, int N)
 
void inlineObserve (uint32_t iters, int N)
 
void notifySubscribers (uint32_t iters, int N)
 
void notifyInlineObservers (uint32_t iters, int N)
 
 BENCHMARK_DRAW_LINE ()
 
int main (int argc, char **argv)
 

Function Documentation

BENCHMARK_DRAW_LINE ( )

Referenced by notifyInlineObservers().

void inlineObserve ( uint32_t  iters,
int  N 
)

Definition at line 74 of file RxBenchmark.cpp.

References folly::BenchmarkSuspender::dismiss(), i, makeObserver(), wangle::Observable< T >::observe(), folly::BenchmarkSuspender::rehire(), and uint32_t.

Referenced by notifyInlineObservers().

74  {
75  for (uint32_t iter = 0; iter < iters; iter++) {
77  Subject<int> subject;
78  std::vector<Observer<int>*> observers;
79  for (int i = 0; i < N; i++) {
80  observers.push_back(makeObserver().release());
81  }
82  bs.dismiss();
83  for (int i = 0; i < N; i++) {
84  subject.observe(observers[i]);
85  }
86  bs.rehire();
87  for (int i = 0; i < N; i++) {
88  delete observers[i];
89  }
90  }
91 }
virtual void observe(ObserverPtr< T > observer)
Definition: Observable.h:68
static std::unique_ptr< Observer< int > > makeObserver()
Definition: RxBenchmark.cpp:25
int main ( int  argc,
char **  argv 
)

Definition at line 151 of file RxBenchmark.cpp.

References argv, and folly::runBenchmarks().

151  {
152  gflags::ParseCommandLineFlags(&argc, &argv, true);
154  return 0;
155 }
void runBenchmarks()
Definition: Benchmark.cpp:456
char ** argv
static std::unique_ptr<Observer<int> > makeObserver ( )
static

Definition at line 25 of file RxBenchmark.cpp.

References wangle::Observer< T >::create().

Referenced by inlineObserve(), notifyInlineObservers(), notifySubscribers(), observe(), and subscribeImpl().

25  {
26  return Observer<int>::create([&] (int) {});
27 }
void notifyInlineObservers ( uint32_t  iters,
int  N 
)

Definition at line 112 of file RxBenchmark.cpp.

References BENCHMARK_DRAW_LINE(), BENCHMARK_PARAM, BENCHMARK_RELATIVE_PARAM, folly::BenchmarkSuspender::dismiss(), i, inlineObserve(), makeObserver(), notifySubscribers(), observe(), wangle::Observable< T >::observe(), wangle::Subject< T >::onNext(), folly::BenchmarkSuspender::rehire(), subscribe(), subscribeAndUnsubscribe(), and uint32_t.

112  {
113  for (uint32_t iter = 0; iter < iters; iter++) {
115  Subject<int> subject;
116  std::vector<Observer<int>*> observers;
117  for (int i = 0; i < N; i++) {
118  observers.push_back(makeObserver().release());
119  }
120  for (int i = 0; i < N; i++) {
121  subject.observe(observers[i]);
122  }
123  bs.dismiss();
124  subject.onNext(42);
125  bs.rehire();
126  }
127 }
virtual void observe(ObserverPtr< T > observer)
Definition: Observable.h:68
static std::unique_ptr< Observer< int > > makeObserver()
Definition: RxBenchmark.cpp:25
void onNext(const T &val) override
Definition: Subject.h:30
void notifySubscribers ( uint32_t  iters,
int  N 
)

Definition at line 93 of file RxBenchmark.cpp.

References folly::BenchmarkSuspender::dismiss(), i, makeObserver(), folly::gen::move, wangle::Subject< T >::onNext(), folly::BenchmarkSuspender::rehire(), wangle::Observable< T >::subscribe(), and uint32_t.

Referenced by notifyInlineObservers().

93  {
94  for (uint32_t iter = 0; iter < iters; iter++) {
96  Subject<int> subject;
97  std::vector<std::unique_ptr<Observer<int>>> observers;
98  std::vector<Subscription<int>> subscriptions;
99  subscriptions.reserve(N);
100  for (int i = 0; i < N; i++) {
101  observers.push_back(makeObserver());
102  }
103  for (int i = 0; i < N; i++) {
104  subscriptions.push_back(subject.subscribe(std::move(observers[i])));
105  }
106  bs.dismiss();
107  subject.onNext(42);
108  bs.rehire();
109  }
110 }
virtual Subscription< T > subscribe(ObserverPtr< T > observer)
Definition: Observable.h:64
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static std::unique_ptr< Observer< int > > makeObserver()
Definition: RxBenchmark.cpp:25
void onNext(const T &val) override
Definition: Subject.h:30
void observe ( uint32_t  iters,
int  N 
)

Definition at line 58 of file RxBenchmark.cpp.

References folly::BenchmarkSuspender::dismiss(), i, makeObserver(), folly::gen::move, wangle::Observable< T >::observe(), folly::BenchmarkSuspender::rehire(), and uint32_t.

Referenced by notifyInlineObservers().

58  {
59  for (uint32_t iter = 0; iter < iters; iter++) {
61  Subject<int> subject;
62  std::vector<std::unique_ptr<Observer<int>>> observers;
63  for (int i = 0; i < N; i++) {
64  observers.push_back(makeObserver());
65  }
66  bs.dismiss();
67  for (int i = 0; i < N; i++) {
68  subject.observe(std::move(observers[i]));
69  }
70  bs.rehire();
71  }
72 }
virtual void observe(ObserverPtr< T > observer)
Definition: Observable.h:68
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static std::unique_ptr< Observer< int > > makeObserver()
Definition: RxBenchmark.cpp:25
void subscribe ( uint32_t  iters,
int  N 
)

Definition at line 54 of file RxBenchmark.cpp.

References subscribeImpl().

Referenced by notifyInlineObservers(), folly::observer::detail::ObserverCreatorContext< Observable, Traits >::subscribe(), TEST(), and TEST_F().

54  {
55  subscribeImpl(iters, N, false);
56 }
void subscribeImpl(uint32_t iters, int N, bool countUnsubscribe)
Definition: RxBenchmark.cpp:29
void subscribeAndUnsubscribe ( uint32_t  iters,
int  N 
)

Definition at line 50 of file RxBenchmark.cpp.

References subscribeImpl().

Referenced by notifyInlineObservers().

50  {
51  subscribeImpl(iters, N, true);
52 }
void subscribeImpl(uint32_t iters, int N, bool countUnsubscribe)
Definition: RxBenchmark.cpp:29
void subscribeImpl ( uint32_t  iters,
int  N,
bool  countUnsubscribe 
)

Definition at line 29 of file RxBenchmark.cpp.

References folly::BenchmarkSuspender::dismiss(), i, makeObserver(), folly::gen::move, folly::BenchmarkSuspender::rehire(), wangle::Observable< T >::subscribe(), and uint32_t.

Referenced by subscribe(), and subscribeAndUnsubscribe().

29  {
30  for (uint32_t iter = 0; iter < iters; iter++) {
32  Subject<int> subject;
33  std::vector<std::unique_ptr<Observer<int>>> observers;
34  std::vector<Subscription<int>> subscriptions;
35  subscriptions.reserve(N);
36  for (int i = 0; i < N; i++) {
37  observers.push_back(makeObserver());
38  }
39  bs.dismiss();
40  for (int i = 0; i < N; i++) {
41  subscriptions.push_back(subject.subscribe(std::move(observers[i])));
42  }
43  if (countUnsubscribe) {
44  subscriptions.clear();
45  }
46  bs.rehire();
47  }
48 }
virtual Subscription< T > subscribe(ObserverPtr< T > observer)
Definition: Observable.h:64
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
static std::unique_ptr< Observer< int > > makeObserver()
Definition: RxBenchmark.cpp:25