proxygen
RefCountBenchmark.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 <thread>
17 
18 #include <folly/Benchmark.h>
20 
21 namespace folly {
22 
23 template <typename Counter>
24 void shutdown(Counter&) {}
25 
27  c.useGlobal();
28  --c;
29 }
30 
31 template <typename Counter, size_t threadCount>
32 void benchmark(size_t n) {
33  Counter x;
34 
35  std::vector<std::thread> ts;
36 
37  for (size_t t = 0; t < threadCount; ++t) {
38  ts.emplace_back([&]() {
39  for (size_t i = 0; i < n; ++i) {
40  ++x;
41  }
42  for (size_t i = 0; i < n; ++i) {
43  --x;
44  }
45  });
46  }
47 
48  for (auto& t : ts) {
49  t.join();
50  }
51 
52  shutdown(x);
53 }
54 
55 BENCHMARK(TLRefCountOneThread, n) {
56  benchmark<TLRefCount, 1>(n);
57 }
58 
59 BENCHMARK(TLRefCountFourThreads, n) {
60  benchmark<TLRefCount, 4>(n);
61 }
62 
63 } // namespace folly
64 
65 int main(int argc, char** argv) {
66  gflags::ParseCommandLineFlags(&argc, &argv, true);
67  gflags::SetCommandLineOptionWithMode(
68  "bm_min_usec", "100000", gflags::SET_FLAG_IF_DEFAULT);
69 
71 
72  return 0;
73 }
int main(int argc, char **argv)
const int x
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
void runBenchmarks()
Definition: Benchmark.cpp:456
char ** argv
void useGlobal() noexcept
Definition: TLRefCount.h:83
void shutdown(Counter &)
void benchmark(size_t n)
BENCHMARK(fbFollyGlobalBenchmarkBaseline)
Definition: Benchmark.cpp:84
char c