]> git.proxmox.com Git - ceph.git/blob - ceph/src/seastar/tests/perf/future_util_perf.cc
import 15.2.0 Octopus source
[ceph.git] / ceph / src / seastar / tests / perf / future_util_perf.cc
1 /*
2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
6 *
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
16 * under the License.
17 */
18 /*
19 * Copyright (C) 2018 ScyllaDB Ltd.
20 */
21
22 #include <boost/range.hpp>
23 #include <boost/range/irange.hpp>
24
25 #include <seastar/testing/perf_tests.hh>
26
27 struct parallel_for_each {
28 std::vector<int> empty_range;
29 std::vector<int> range;
30 int value;
31
32 parallel_for_each()
33 : empty_range()
34 , range(boost::copy_range<std::vector<int>>(boost::irange(1, 100)))
35 { }
36 };
37
38 PERF_TEST_F(parallel_for_each, empty)
39 {
40 return seastar::parallel_for_each(empty_range, [] (int) -> future<> {
41 abort();
42 });
43 }
44
45 [[gnu::noinline]]
46 future<> immediate(int v, int& vs)
47 {
48 vs += v;
49 return make_ready_future<>();
50 }
51
52 PERF_TEST_F(parallel_for_each, immediate)
53 {
54 return seastar::parallel_for_each(range, [this] (int v) {
55 return immediate(v, value);
56 }).then([this] {
57 perf_tests::do_not_optimize(value);
58 });
59 }
60
61 [[gnu::noinline]]
62 future<> suspend(int v, int& vs)
63 {
64 vs += v;
65 return later();
66 }
67
68 PERF_TEST_F(parallel_for_each, suspend)
69 {
70 return seastar::parallel_for_each(range, [this] (int v) {
71 return suspend(v, value);
72 }).then([this] {
73 perf_tests::do_not_optimize(value);
74 });
75 }