proxygen
BlockingWaitBenchmark.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017-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 
17 #include <folly/Benchmark.h>
18 #include <folly/Portability.h>
19 
20 #if FOLLY_HAS_COROUTINES
21 
24 
25 #include <string>
26 
27 BENCHMARK(blockingWaitRVOInt, iters) {
28  for (size_t iter = 0; iter < iters; ++iter) {
29  auto result =
31  if (result != 42) {
32  std::abort();
33  }
34  }
35 }
36 
37 constexpr folly::StringPiece longString =
38  "hello coroutines! this is a longer string that "
39  "should hopefully inhibit short string optimisations.";
40 
41 BENCHMARK(blockingWaitRVOStrings, iters) {
42  for (size_t iter = 0; iter < iters; ++iter) {
43  auto result = folly::coro::blockingWait(
45  if (result.size() != longString.size()) {
46  std::abort();
47  }
48  }
49 }
50 
51 struct IdentityMatrix {};
52 
53 struct Matrix {
54  /* implicit */ Matrix(IdentityMatrix) noexcept {
55  for (int i = 0; i < 4; ++i) {
56  for (int j = 0; j < 4; ++j) {
57  values_[i][j] = (i == j) ? 1 : 0;
58  }
59  }
60  }
61 
62  Matrix(const Matrix&) noexcept = default;
63  Matrix& operator=(const Matrix&) noexcept = default;
64 
65  std::uint64_t values_[4][4];
66 };
67 
68 BENCHMARK(blockingWaitRVO, iters) {
69  folly::coro::AwaitableReady<Matrix> identityAwaitable{IdentityMatrix{}};
70  for (size_t iter = 0; iter < iters; ++iter) {
71  auto result = folly::coro::blockingWait(identityAwaitable);
72  if (result.values_[3][3] != 1) {
73  std::abort();
74  }
75  }
76 }
77 
78 #endif
79 
80 int main(int argc, char** argv) {
81  gflags::ParseCommandLineFlags(&argc, &argv, true);
83  return 0;
84 }
STL namespace.
void runBenchmarks()
Definition: Benchmark.cpp:456
requires E e noexcept(noexcept(s.error(std::move(e))))
char ** argv
int main(int argc, char **argv)
#define BENCHMARK(name,...)
Definition: Benchmark.h:365
const
Definition: upload.py:398
default
Definition: upload.py:394
auto blockingWait(Awaitable &&awaitable) -> detail::decay_rvalue_reference_t< await_result_t< Awaitable >>
Definition: BlockingWait.h:313