• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Abseil Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "absl/synchronization/internal/graphcycles.h"
16 
17 #include <algorithm>
18 #include <cstdint>
19 #include <vector>
20 
21 #include "benchmark/benchmark.h"
22 #include "absl/base/internal/raw_logging.h"
23 
24 namespace {
25 
BM_StressTest(benchmark::State & state)26 void BM_StressTest(benchmark::State& state) {
27   const int num_nodes = state.range(0);
28   while (state.KeepRunningBatch(num_nodes)) {
29     absl::synchronization_internal::GraphCycles g;
30     std::vector<absl::synchronization_internal::GraphId> nodes(num_nodes);
31     for (int i = 0; i < num_nodes; i++) {
32       nodes[i] = g.GetId(reinterpret_cast<void*>(static_cast<uintptr_t>(i)));
33     }
34     for (int i = 0; i < num_nodes; i++) {
35       int end = std::min(num_nodes, i + 5);
36       for (int j = i + 1; j < end; j++) {
37         ABSL_RAW_CHECK(g.InsertEdge(nodes[i], nodes[j]), "");
38       }
39     }
40   }
41 }
42 BENCHMARK(BM_StressTest)->Range(2048, 1048576);
43 
44 }  // namespace
45