ThreadCachedIntsBenchmark.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright 2018-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>
  17. #include <folly/synchronization/detail/ThreadCachedInts.h>
  18. using namespace folly;
  19. void runTest(int iters) {
  20. BenchmarkSuspender susp;
  21. detail::ThreadCachedInts<void> counters;
  22. counters.increment(0);
  23. susp.dismiss();
  24. // run the test loop
  25. for (int i = 0; i < iters; i++) {
  26. counters.increment(0);
  27. }
  28. }
  29. BENCHMARK_DRAW_LINE();
  30. BENCHMARK(Increment, iters) {
  31. runTest(iters);
  32. }
  33. BENCHMARK_DRAW_LINE();
  34. int main(int argc, char* argv[]) {
  35. gflags::ParseCommandLineFlags(&argc, &argv, true);
  36. folly::runBenchmarks();
  37. return 0;
  38. }