proxygen
EventBaseBenchmark.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2015-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include <folly/Benchmark.h>
19 
20 using namespace folly;
21 
23  public:
24  CountedLoopCallback(EventBase* eventBase, unsigned int count)
25  : eventBase_(eventBase), count_(count) {}
26 
27  void runLoopCallback() noexcept override {
28  --count_;
29  if (count_ > 0) {
30  eventBase_->runInLoop(this);
31  }
32  }
33 
34  private:
36  unsigned int count_;
37 };
38 
39 BENCHMARK(timeMeasurementsOn, n) {
40  EventBase eventBase;
41 
42  while (n--) {
43  CountedLoopCallback c(&eventBase, 10);
44  eventBase.runInLoop(&c);
45  eventBase.loop();
46  }
47 }
48 
49 BENCHMARK_RELATIVE(timeMeasurementsOff, n) {
50  EventBase eventBase(/* enableTimeMeasurement */ false);
51 
52  while (n--) {
53  CountedLoopCallback c(&eventBase, 10);
54  eventBase.runInLoop(&c);
55  eventBase.loop();
56  }
57 }
58 
70 int main(int argc, char** argv) {
71  gflags::ParseCommandLineFlags(&argc, &argv, true);
72  runBenchmarks();
73 }
CountedLoopCallback(EventBase *eventBase, unsigned int count)
int main(int argc, char **argv)
BENCHMARK_RELATIVE(timeMeasurementsOff, n)
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
void runBenchmarks()
Definition: Benchmark.cpp:456
requires E e noexcept(noexcept(s.error(std::move(e))))
char ** argv
void runInLoop(LoopCallback *callback, bool thisIteration=false)
Definition: EventBase.cpp:520
int * count
BENCHMARK(fbFollyGlobalBenchmarkBaseline)
Definition: Benchmark.cpp:84
void runLoopCallback() noexceptoverride
char c