graphcycles_benchmark.cc (1463B)
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 <algorithm> 16 #include <cstdint> 17 #include <vector> 18 19 #include "absl/base/internal/raw_logging.h" 20 #include "absl/synchronization/internal/graphcycles.h" 21 #include "benchmark/benchmark.h" 22 23 namespace { 24 25 void BM_StressTest(benchmark::State& state) { 26 const int num_nodes = state.range(0); 27 while (state.KeepRunningBatch(num_nodes)) { 28 absl::synchronization_internal::GraphCycles g; 29 std::vector<absl::synchronization_internal::GraphId> nodes(num_nodes); 30 for (int i = 0; i < num_nodes; i++) { 31 nodes[i] = g.GetId(reinterpret_cast<void*>(static_cast<uintptr_t>(i))); 32 } 33 for (int i = 0; i < num_nodes; i++) { 34 int end = std::min(num_nodes, i + 5); 35 for (int j = i + 1; j < end; j++) { 36 ABSL_RAW_CHECK(g.InsertEdge(nodes[i], nodes[j]), ""); 37 } 38 } 39 } 40 } 41 BENCHMARK(BM_StressTest)->Range(2048, 1048576); 42 43 } // namespace