graphcycles_benchmark.cc
Go to the documentation of this file.
00001 // Copyright 2018 The Abseil Authors.
00002 //
00003 // Licensed under the Apache License, Version 2.0 (the "License");
00004 // you may not use this file except in compliance with the License.
00005 // You may obtain a copy of the License at
00006 //
00007 //      https://www.apache.org/licenses/LICENSE-2.0
00008 //
00009 // Unless required by applicable law or agreed to in writing, software
00010 // distributed under the License is distributed on an "AS IS" BASIS,
00011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 // See the License for the specific language governing permissions and
00013 // limitations under the License.
00014 
00015 #include "absl/synchronization/internal/graphcycles.h"
00016 
00017 #include <algorithm>
00018 #include <cstdint>
00019 #include <vector>
00020 
00021 #include "benchmark/benchmark.h"
00022 #include "absl/base/internal/raw_logging.h"
00023 
00024 namespace {
00025 
00026 void BM_StressTest(benchmark::State& state) {
00027   const int num_nodes = state.range(0);
00028   while (state.KeepRunningBatch(num_nodes)) {
00029     absl::synchronization_internal::GraphCycles g;
00030     std::vector<absl::synchronization_internal::GraphId> nodes(num_nodes);
00031     for (int i = 0; i < num_nodes; i++) {
00032       nodes[i] = g.GetId(reinterpret_cast<void*>(static_cast<uintptr_t>(i)));
00033     }
00034     for (int i = 0; i < num_nodes; i++) {
00035       int end = std::min(num_nodes, i + 5);
00036       for (int j = i + 1; j < end; j++) {
00037         ABSL_RAW_CHECK(g.InsertEdge(nodes[i], nodes[j]), "");
00038       }
00039     }
00040   }
00041 }
00042 BENCHMARK(BM_StressTest)->Range(2048, 1048576);
00043 
00044 }  // namespace


abseil_cpp
Author(s):
autogenerated on Wed Jun 19 2019 19:42:14