Skip to content

Commit

Permalink
add benchmark for find_root
Browse files Browse the repository at this point in the history
  • Loading branch information
etwest committed Feb 24, 2024
1 parent 91106f6 commit 3d8cf14
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/return_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ std::vector<std::set<node_id_t>> ConnectedComponents::get_component_sets() {
SpanningForest::SpanningForest(node_id_t num_vertices,
const std::unordered_set<node_id_t> *spanning_forest)
: num_vertices(num_vertices) {
edges.reserve(num_vertices);
for (node_id_t src = 0; src < num_vertices; src++) {
for (node_id_t dst : spanning_forest[src]) {
edges.push_back({src, dst});
Expand Down
2 changes: 1 addition & 1 deletion test/util/mat_graph_verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void MatGraphVerifier::edge_update(node_id_t src, node_id_t dst) {
// update adj_matrix entry
adj_matrix[src][dst] = !adj_matrix[src][dst];
}


void MatGraphVerifier::reset_cc_state() {
kruskal_ref = kruskal();
Expand Down
99 changes: 99 additions & 0 deletions tools/benchmark/graphcc_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,105 @@ BENCHMARK(BM_Sketch_Serialize)->RangeMultiplier(10)->Range(1e3, 1e6);
// }
// BENCHMARK(BM_Sketch_Sparse_Serialize)->RangeMultiplier(10)->Range(1e3, 1e6);

// Benchmark DSU Find Root
static void BM_DSU_Find(benchmark::State& state) {
constexpr size_t size_of_dsu = 16 * MB;
DisjointSetUnion<node_id_t> dsu(size_of_dsu);

auto rng = std::default_random_engine{};
std::vector<node_id_t> queries;
for (size_t i = 0; i < 4096; i++) {
queries.push_back((size_of_dsu / 4096) * i);
}
std::shuffle(queries.begin(), queries.end(), rng);

// perform find test
for (auto _ : state) {
for (auto q : queries)
dsu.find_root(q);
}
state.counters["Find_Latency"] =
benchmark::Counter(state.iterations() * queries.size(),
benchmark::Counter::kIsRate | benchmark::Counter::kInvert);
}
BENCHMARK(BM_DSU_Find);

static void BM_DSU_Find_After_Combine(benchmark::State& state) {
constexpr size_t size_of_dsu = 16 * MB;
DisjointSetUnion<node_id_t> dsu(size_of_dsu);
// merge everything into same root
for (size_t i = 0; i < size_of_dsu - 1; i++) {
dsu.merge(i, i+1);
}

auto rng = std::default_random_engine{};
std::vector<node_id_t> queries;
for (size_t i = 0; i < 4096; i++) {
queries.push_back((size_of_dsu / 4096) * i);
}
std::shuffle(queries.begin(), queries.end(), rng);

// perform find test
for (auto _ : state) {
for (auto q : queries)
dsu.find_root(q);
}
state.counters["Find_Latency"] =
benchmark::Counter(state.iterations() * queries.size(),
benchmark::Counter::kIsRate | benchmark::Counter::kInvert);
}
BENCHMARK(BM_DSU_Find_After_Combine);

// MT DSU Find Root
static void BM_MT_DSU_Find(benchmark::State& state) {
constexpr size_t size_of_dsu = 16 * MB;
DisjointSetUnion_MT<node_id_t> dsu(size_of_dsu);

auto rng = std::default_random_engine{};
std::vector<node_id_t> queries;
for (size_t i = 0; i < 4096; i++) {
queries.push_back((size_of_dsu / 4096) * i);
}
std::shuffle(queries.begin(), queries.end(), rng);

// perform find test
for (auto _ : state) {
for (auto q : queries)
dsu.find_root(q);
}
state.counters["Find_Latency"] =
benchmark::Counter(state.iterations() * queries.size(),
benchmark::Counter::kIsRate | benchmark::Counter::kInvert);
}
BENCHMARK(BM_MT_DSU_Find);

// MT DSU Find Root
static void BM_MT_DSU_Find_After_Combine(benchmark::State& state) {
constexpr size_t size_of_dsu = MB;
DisjointSetUnion_MT<node_id_t> dsu(size_of_dsu);
// merge everything into same root
for (size_t i = 0; i < size_of_dsu - 1; i++) {
dsu.merge(i, i+1);
}

auto rng = std::default_random_engine{};
std::vector<node_id_t> queries;
for (size_t i = 0; i < 512; i++) {
queries.push_back((size_of_dsu / 512) * i);
}
std::shuffle(queries.begin(), queries.end(), rng);

// perform find test
for (auto _ : state) {
for (auto q : queries)
dsu.find_root(q);
}
state.counters["Find_Latency"] =
benchmark::Counter(state.iterations() * queries.size(),
benchmark::Counter::kIsRate | benchmark::Counter::kInvert);
}
BENCHMARK(BM_MT_DSU_Find_After_Combine);

// Benchmark speed of DSU merges when the sequence of merges is adversarial
// This means we avoid joining roots wherever possible
static void BM_DSU_Adversarial(benchmark::State& state) {
Expand Down

0 comments on commit 3d8cf14

Please sign in to comment.