From 500ed0801d145984e1d387c9138851f9ac2046c0 Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Tue, 16 Jun 2026 14:07:27 -0500 Subject: [PATCH 01/24] save local changes before pull --- raphtory-benchmark/benches/algobench.rs | 17 +++++++++++++++++ raphtory/src/algorithms/centrality/pagerank.rs | 8 +++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/raphtory-benchmark/benches/algobench.rs b/raphtory-benchmark/benches/algobench.rs index cb78c4c657..6526ba5768 100644 --- a/raphtory-benchmark/benches/algobench.rs +++ b/raphtory-benchmark/benches/algobench.rs @@ -50,6 +50,22 @@ pub fn local_clustering_coefficient_analysis(c: &mut Criterion) { group.finish(); } +pub fn page_rank_analysis(c: &mut Criterion) { + let mut group = c.benchmark_group("page_rank"); + group.sample_size(10); + + bench(&mut group, "page_rank", None, |b| { + let g: Graph = raphtory::graph_loader::lotr_graph::lotr_graph(); + + b.iter(|| { + let result = unweighted_page_rank(&g, Some(100), None, None, true, None); + black_box(result); + }) + }); + + group.finish(); +} + pub fn graphgen_large_clustering_coeff(c: &mut Criterion) { let mut group = c.benchmark_group("graphgen_large_clustering_coeff"); // generate graph @@ -135,6 +151,7 @@ criterion_group!( benches, local_triangle_count_analysis, local_clustering_coefficient_analysis, + page_rank_analysis, graphgen_large_clustering_coeff, graphgen_large_pagerank, graphgen_large_concomp, diff --git a/raphtory/src/algorithms/centrality/pagerank.rs b/raphtory/src/algorithms/centrality/pagerank.rs index c8db2077a2..58c03abe0f 100644 --- a/raphtory/src/algorithms/centrality/pagerank.rs +++ b/raphtory/src/algorithms/centrality/pagerank.rs @@ -11,7 +11,7 @@ use crate::{ task_runner::TaskRunner, }, }, - prelude::GraphViewOps, + prelude::GraphViewOps, python::graph::node_state::NodeFilter, }; use num_traits::abs; use serde::{Deserialize, Serialize}; @@ -22,6 +22,8 @@ pub struct PageRankState { pub score: f64, #[serde(skip)] out_degree: usize, + nbor_score: f64, + num_in_nbors: usize, } impl PageRankState { @@ -29,6 +31,8 @@ impl PageRankState { Self { score: 1f64 / num_nodes as f64, out_degree: 0, + nbor_score: 0f64, + num_in_nbors: 0, } } fn reset(&mut self) { @@ -61,6 +65,7 @@ pub fn unweighted_page_rank( damping_factor: Option, ) -> TypedNodeState<'static, PageRankState, G> { let n = g.count_nodes(); + let f_g = g.select(NodeFilter.in_degree()); let mut ctx: Context = g.into(); @@ -82,6 +87,7 @@ pub fn unweighted_page_rank( let out_degree = s.out_degree(); let state: &mut PageRankState = s.get_mut(); state.out_degree = out_degree; + state.num_in_nbors = s.in_degree(); Step::Continue }); From 0288deb3d86cdefa2e54d60033dfbf8a736d1ca2 Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Tue, 16 Jun 2026 22:23:27 -0500 Subject: [PATCH 02/24] working on algorithm --- raphtory/src/algorithms/centrality/mod.rs | 1 + .../src/algorithms/centrality/new_pagerank.rs | 231 ++++++++++++++++++ .../src/algorithms/centrality/pagerank.rs | 1 - 3 files changed, 232 insertions(+), 1 deletion(-) create mode 100644 raphtory/src/algorithms/centrality/new_pagerank.rs diff --git a/raphtory/src/algorithms/centrality/mod.rs b/raphtory/src/algorithms/centrality/mod.rs index 64fce608c6..dc87e2bfeb 100644 --- a/raphtory/src/algorithms/centrality/mod.rs +++ b/raphtory/src/algorithms/centrality/mod.rs @@ -2,3 +2,4 @@ pub mod betweenness; pub mod degree_centrality; pub mod hits; pub mod pagerank; +pub mod new_pagerank; diff --git a/raphtory/src/algorithms/centrality/new_pagerank.rs b/raphtory/src/algorithms/centrality/new_pagerank.rs new file mode 100644 index 0000000000..9b6ed0d61c --- /dev/null +++ b/raphtory/src/algorithms/centrality/new_pagerank.rs @@ -0,0 +1,231 @@ +use crate::{ + core::state::{accumulator_id::accumulators, compute_state::ComputeStateVec}, + db::{ + api::{ + state::{GenericNodeState, TypedNodeState}, + view::{EdgeViewOps, NodeViewOps, StaticGraphViewOps, filter_ops::NodeSelect}, + }, graph::views::node_subgraph::NodeSubgraph, task::{ + context::Context, + task::{ATask, Job, Step}, + task_runner::TaskRunner, + } + }, + prelude::{GraphViewOps, PropertiesOps}, +}; +use num_traits::abs; +use raphtory_api::core::entities::properties::prop::PropUnwrap; +use serde::{Deserialize, Serialize}; +use crate::prelude::NodeFilter; +use crate::db::graph::views::filter::model::degree_filter::DegreeFilterFactory; +use crate::db::graph::views::filter::model::property_filter::ops::PropertyFilterOps; + +#[derive(Clone, PartialEq, Serialize, Deserialize, Debug, Default)] +pub struct PageRankState { + #[serde(rename = "pagerank_score")] + pub score: f64, + #[serde(skip)] + weighted_out_degree: f64, + special_neighbor_weight: f64 +} + +impl PageRankState { + fn new(num_nodes: usize) -> Self { + Self { + score: 1f64 / num_nodes as f64, + weighted_out_degree: 0f64, + special_neighbor_weight: 0.0 + } + } + + fn reset(&mut self) { + self.score = 0f64; + } +} + +/// PageRank Algorithm: +/// PageRank shows how important a node is in a graph. +/// +/// # Arguments +/// +/// - `g`: A GraphView object +/// - `weight`: Edge property key to use as weight. If None, all edges have weight 1.0. +/// - `iter_count`: Number of iterations to run the algorithm for +/// - `threads`: Number of threads to use for parallel execution +/// - `tol`: The tolerance value for convergence +/// - `use_l2_norm`: Whether to use L2 norm for convergence +/// - `damping_factor`: Probability of likelihood the spread will continue +/// +/// # Returns +/// +/// An [AlgorithmResult] object containing the mapping from node ID to the PageRank score of the node +/// +pub fn page_rank( + g: &G, + weight: Option<&str>, + iter_count: Option, + threads: Option, + tol: Option, + use_l2_norm: bool, + damping_factor: Option, +) -> TypedNodeState<'static, PageRankState, NodeSubgraph> { + let n = g.count_nodes(); + let not_special_neighbors = g.nodes().select(NodeFilter.in_degree().eq(0)).unwrap(); + let f_g = g.subgraph(not_special_neighbors); + + let mut ctx: Context = g.into(); + + let tol: f64 = tol.unwrap_or(0.000001f64); + let damp = damping_factor.unwrap_or(0.85); + let iter_count = iter_count.unwrap_or(20); + let teleport_prob = (1f64 - damp) / n as f64; + let factor = damp / n as f64; + + let max_diff = accumulators::sum::(2); + + let total_sink_contribution = accumulators::sum::(4); + + ctx.global_agg_reset(max_diff); + + ctx.global_agg_reset(total_sink_contribution); + + let weight_id = weight.and_then(|key| g.edge_meta().get_prop_id(key, false)); + + let step1 = ATask::new({ + move |s| { + let s_node = g.node(&s.node).unwrap(); + let weighted_out_degree = s_node.out_edges().iter().fold(0.0f64, |acc, edge| { + weight_id + .and_then(|id| edge.properties().get_by_id(id)) + .and_then(|p| p.as_f64()) + .unwrap_or(1.0) + + acc + }); + let state: &mut PageRankState = s.get_mut(); + state.weighted_out_degree = weighted_out_degree; + let special_neighbor_weight = s_node.in_edges().iter().fold(0.0f64, |acc, edge| { + let nbr = edge.nbr(); + if nbr.in_degree() == 0 { + let weighted_out_degree = nbr.out_edges().iter().fold(0.0f64, |acc, edge| { + weight_id + .and_then(|id| edge.properties().get_by_id(id)) + .and_then(|p| p.as_f64()) + .unwrap_or(1.0) + + acc + + }); + if weighted_out_degree > 0.0 { + let w = weight_id + .and_then(|id| edge.properties().get_by_id(id)) + .and_then(|p| p.as_f64()) + .unwrap_or(1.0); + acc + w / weighted_out_degree + } else { + acc + } + } else { + acc + } + }); + Step::Continue + } + }); + + let step2: ATask = ATask::new(move |s| { + // reset score + { + let state: &mut PageRankState = s.get_mut(); + state.reset(); + } + + for edge in s.in_edges() { + let w = weight_id + .and_then(|id| edge.properties().get_by_id(id)) + .and_then(|p| p.as_f64()) + .unwrap_or(1.0); + let nbr = edge.nbr(); + let prev = nbr.prev(); + + if prev.weighted_out_degree > 0.0 { + s.get_mut().score += prev.score * w / prev.weighted_out_degree; + } + } + + s.get_mut().score *= damp; + + s.get_mut().score += teleport_prob; + Step::Continue + }); + + let step3 = ATask::new(move |s| { + let state: &mut PageRankState = s.get_mut(); + + if state.weighted_out_degree.abs() < f64::EPSILON { + let curr = s.prev().score; + + let ts_contrib = factor * curr; + s.global_update(&total_sink_contribution, ts_contrib); + } + Step::Continue + }); + + let step4 = ATask::new(move |s| { + //read total sink contribution + let total_sink_contribution = s + .read_global_state(&total_sink_contribution) + .unwrap_or_default(); + // update local score with total sink contribution + let state: &mut PageRankState = s.get_mut(); + state.score += total_sink_contribution; + + // update global max diff + + let curr = state.score; + let prev = s.prev().score; + + let md = if use_l2_norm { + f64::powi(abs(prev - curr), 2) + } else { + abs(prev - curr) + }; + + s.global_update(&max_diff, md); + Step::Continue + }); + + let step5 = Job::Check(Box::new(move |state| { + let max_diff_val = state.read(&max_diff); + let cont = if use_l2_norm { + let sum_d = f64::sqrt(max_diff_val); + (sum_d) > tol * n as f64 + } else { + (max_diff_val) > tol * n as f64 + }; + if cont { + Step::Continue + } else { + Step::Done + } + })); + + let mut runner: TaskRunner = TaskRunner::new(ctx); + + let num_nodes = g.count_nodes(); + + runner.run( + vec![Job::new(step1)], + vec![Job::new(step2), Job::new(step3), Job::new(step4), step5], + Some(vec![PageRankState::new(num_nodes); num_nodes]), + |_, _, _, local, index| { + TypedNodeState::new(GenericNodeState::new_from_eval_with_index( + f_g.clone(), + local, + index, + None, + )) + }, + threads, + iter_count, + None, + None, + ) +} diff --git a/raphtory/src/algorithms/centrality/pagerank.rs b/raphtory/src/algorithms/centrality/pagerank.rs index 4409df61a9..bf52713689 100644 --- a/raphtory/src/algorithms/centrality/pagerank.rs +++ b/raphtory/src/algorithms/centrality/pagerank.rs @@ -65,7 +65,6 @@ pub fn page_rank( damping_factor: Option, ) -> TypedNodeState<'static, PageRankState, G> { let n = g.count_nodes(); - let f_g = g.select(NodeFilter.in_degree()); let mut ctx: Context = g.into(); From 605f91e5ce82cac9540f07f667dba792909204c2 Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Wed, 17 Jun 2026 00:12:48 -0500 Subject: [PATCH 03/24] working --- .../src/algorithms/centrality/new_pagerank.rs | 69 +++++++++++++------ 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/raphtory/src/algorithms/centrality/new_pagerank.rs b/raphtory/src/algorithms/centrality/new_pagerank.rs index 9b6ed0d61c..07d862ae08 100644 --- a/raphtory/src/algorithms/centrality/new_pagerank.rs +++ b/raphtory/src/algorithms/centrality/new_pagerank.rs @@ -18,6 +18,8 @@ use serde::{Deserialize, Serialize}; use crate::prelude::NodeFilter; use crate::db::graph::views::filter::model::degree_filter::DegreeFilterFactory; use crate::db::graph::views::filter::model::property_filter::ops::PropertyFilterOps; +use std::collections::HashMap; +use raphtory_api::core::entities::VID; #[derive(Clone, PartialEq, Serialize, Deserialize, Debug, Default)] pub struct PageRankState { @@ -25,20 +27,23 @@ pub struct PageRankState { pub score: f64, #[serde(skip)] weighted_out_degree: f64, - special_neighbor_weight: f64 + special_neighbor_weight: f64, + special_node_score: f64, } impl PageRankState { fn new(num_nodes: usize) -> Self { Self { score: 1f64 / num_nodes as f64, + special_node_score: 1f64 / num_nodes as f64, weighted_out_degree: 0f64, - special_neighbor_weight: 0.0 + special_neighbor_weight: 0.0, } } fn reset(&mut self) { self.score = 0f64; + self.special_node_score = 0f64; } } @@ -84,14 +89,36 @@ pub fn page_rank( let total_sink_contribution = accumulators::sum::(4); + ctx.global_agg_reset(max_diff); ctx.global_agg_reset(total_sink_contribution); - + let weight_id = weight.and_then(|key| g.edge_meta().get_prop_id(key, false)); + let mut special_node_sink_contributor_count = 0; + + let mut special_node_out_degrees: HashMap = HashMap::new(); + for node in g.nodes() { + if node.in_degree() == 0 { + let weighted_out_degree = node.out_edges().iter().fold(0.0f64, |acc, edge| { + weight_id + .and_then(|id| edge.properties().get_by_id(id)) + .and_then(|p| p.as_f64()) + .unwrap_or(1.0) + + acc + }); + if (weighted_out_degree.abs() < f64::EPSILON) { + special_node_sink_contributor_count += 1; + } + special_node_out_degrees.insert(node.node, weighted_out_degree); + } + } + + let step1 = ATask::new({ move |s| { + let special_node_out_degrees = s.read_global_state(&special_node_out_degrees).unwrap(); let s_node = g.node(&s.node).unwrap(); let weighted_out_degree = s_node.out_edges().iter().fold(0.0f64, |acc, edge| { weight_id @@ -104,28 +131,21 @@ pub fn page_rank( state.weighted_out_degree = weighted_out_degree; let special_neighbor_weight = s_node.in_edges().iter().fold(0.0f64, |acc, edge| { let nbr = edge.nbr(); - if nbr.in_degree() == 0 { - let weighted_out_degree = nbr.out_edges().iter().fold(0.0f64, |acc, edge| { - weight_id - .and_then(|id| edge.properties().get_by_id(id)) - .and_then(|p| p.as_f64()) - .unwrap_or(1.0) - + acc - - }); - if weighted_out_degree > 0.0 { - let w = weight_id - .and_then(|id| edge.properties().get_by_id(id)) - .and_then(|p| p.as_f64()) - .unwrap_or(1.0); - acc + w / weighted_out_degree + if let Some(&weighted_out_degree) = special_node_out_degrees.get(&nbr.node) { + if weighted_out_degree > 0.0 { + let w = weight_id + .and_then(|id| edge.properties().get_by_id(id)) + .and_then(|p| p.as_f64()) + .unwrap_or(1.0); + acc + w / weighted_out_degree + } else { + acc + } } else { acc } - } else { - acc - } }); + state.special_neighbor_weight = special_neighbor_weight; Step::Continue } }); @@ -136,6 +156,8 @@ pub fn page_rank( let state: &mut PageRankState = s.get_mut(); state.reset(); } + + let special_node_score = s.prev().special_node_score; for edge in s.in_edges() { let w = weight_id @@ -149,10 +171,15 @@ pub fn page_rank( s.get_mut().score += prev.score * w / prev.weighted_out_degree; } } + s.get_mut().score += s.prev().special_neighbor_weight * special_node_score; s.get_mut().score *= damp; s.get_mut().score += teleport_prob; + + s.get_mut().special_node_score *= damp; + + s.get_mut().special_node_score += teleport_prob; Step::Continue }); From 87aee842e5b7d56046f980b5fd472123f1f9abd6 Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Wed, 17 Jun 2026 10:15:23 -0500 Subject: [PATCH 04/24] working --- raphtory/src/algorithms/centrality/new_pagerank.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/raphtory/src/algorithms/centrality/new_pagerank.rs b/raphtory/src/algorithms/centrality/new_pagerank.rs index 07d862ae08..05ebcf8bb3 100644 --- a/raphtory/src/algorithms/centrality/new_pagerank.rs +++ b/raphtory/src/algorithms/centrality/new_pagerank.rs @@ -29,6 +29,7 @@ pub struct PageRankState { weighted_out_degree: f64, special_neighbor_weight: f64, special_node_score: f64, + special_node_sink_contributor_count: usize, } impl PageRankState { @@ -38,6 +39,7 @@ impl PageRankState { special_node_score: 1f64 / num_nodes as f64, weighted_out_degree: 0f64, special_neighbor_weight: 0.0, + special_node_sink_contributor_count: 0, } } @@ -97,7 +99,6 @@ pub fn page_rank( let weight_id = weight.and_then(|key| g.edge_meta().get_prop_id(key, false)); let mut special_node_sink_contributor_count = 0; - let mut special_node_out_degrees: HashMap = HashMap::new(); for node in g.nodes() { if node.in_degree() == 0 { @@ -118,7 +119,6 @@ pub fn page_rank( let step1 = ATask::new({ move |s| { - let special_node_out_degrees = s.read_global_state(&special_node_out_degrees).unwrap(); let s_node = g.node(&s.node).unwrap(); let weighted_out_degree = s_node.out_edges().iter().fold(0.0f64, |acc, edge| { weight_id @@ -201,8 +201,10 @@ pub fn page_rank( .read_global_state(&total_sink_contribution) .unwrap_or_default(); // update local score with total sink contribution + let total_sink_contribution = total_sink_contribution + s.prev().special_node_sink_contributor_count as f64 * factor * s.prev().special_node_score; let state: &mut PageRankState = s.get_mut(); state.score += total_sink_contribution; + state.special_node_score += total_sink_contribution; // update global max diff From 679911454063e102c11bfe3a0d795b20b5798dec Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Wed, 17 Jun 2026 10:15:47 -0500 Subject: [PATCH 05/24] working --- raphtory-benchmark/benches/algobench.rs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/raphtory-benchmark/benches/algobench.rs b/raphtory-benchmark/benches/algobench.rs index 7709962eda..d9dccab5fb 100644 --- a/raphtory-benchmark/benches/algobench.rs +++ b/raphtory-benchmark/benches/algobench.rs @@ -50,21 +50,7 @@ pub fn local_clustering_coefficient_analysis(c: &mut Criterion) { group.finish(); } -pub fn page_rank_analysis(c: &mut Criterion) { - let mut group = c.benchmark_group("page_rank"); - group.sample_size(10); - - bench(&mut group, "page_rank", None, |b| { - let g: Graph = raphtory::graph_loader::lotr_graph::lotr_graph(); - b.iter(|| { - let result = unweighted_page_rank(&g, Some(100), None, None, true, None); - black_box(result); - }) - }); - - group.finish(); -} pub fn graphgen_large_clustering_coeff(c: &mut Criterion) { let mut group = c.benchmark_group("graphgen_large_clustering_coeff"); @@ -151,7 +137,6 @@ criterion_group!( benches, local_triangle_count_analysis, local_clustering_coefficient_analysis, - page_rank_analysis, graphgen_large_clustering_coeff, graphgen_large_pagerank, graphgen_large_concomp, From 9a03c33e89aaf46dca192c4dd46e4251da026c2b Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Thu, 18 Jun 2026 14:12:55 -0500 Subject: [PATCH 06/24] working --- raphtory-benchmark/benches/algobench.rs | 1174 ++++++++++++++++- raphtory/src/algorithms/centrality/mod.rs | 1 - .../src/algorithms/centrality/new_pagerank.rs | 260 ---- 3 files changed, 1128 insertions(+), 307 deletions(-) delete mode 100644 raphtory/src/algorithms/centrality/new_pagerank.rs diff --git a/raphtory-benchmark/benches/algobench.rs b/raphtory-benchmark/benches/algobench.rs index d9dccab5fb..91b0cb5893 100644 --- a/raphtory-benchmark/benches/algobench.rs +++ b/raphtory-benchmark/benches/algobench.rs @@ -1,38 +1,187 @@ use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, SamplingMode}; +use rand::{rngs::SmallRng, SeedableRng}; use raphtory::{ algorithms::{ - centrality::pagerank::page_rank, - components::weakly_connected_components, - metrics::clustering_coefficient::{ - global_clustering_coefficient::global_clustering_coefficient, - local_clustering_coefficient::local_clustering_coefficient, + alternating_mask::alternating_mask, + bipartite::max_weight_matching::max_weight_matching, + centrality::{ + betweenness::betweenness_centrality, degree_centrality::degree_centrality, + hits::hits, new_pagerank::page_rank as new_page_rank, pagerank::page_rank, + }, + community_detection::{ + label_propagation::label_propagation, + louvain::louvain, + modularity::ModularityUnDir, + }, + components::{ + in_component, in_component_filtered, in_components, in_components_filtered, + out_component, out_component_filtered, out_components, out_components_filtered, + strongly_connected_components, weakly_connected_components, + }, + cores::k_core::{k_core, k_core_set}, + dynamics::temporal::epidemics::{temporal_SEIR, Number}, + embeddings::fast_rp::fast_rp, + layout::{ + cohesive_fruchterman_reingold::cohesive_fruchterman_reingold, + fruchterman_reingold::fruchterman_reingold_unbounded, + }, + metrics::{ + balance::balance, + clustering_coefficient::{ + global_clustering_coefficient::global_clustering_coefficient, + local_clustering_coefficient::local_clustering_coefficient, + local_clustering_coefficient_batch::local_clustering_coefficient_batch, + }, + degree::{ + average_degree, max_degree, max_in_degree, max_out_degree, min_degree, + min_in_degree, min_out_degree, + }, + directed_graph_density::directed_graph_density, + reciprocity::{all_local_reciprocity, global_reciprocity}, }, motifs::{ - global_temporal_three_node_motifs::global_temporal_three_node_motif, + global_temporal_three_node_motifs::{ + global_temporal_three_node_motif, temporal_three_node_motif_multi, + triangle_motifs as global_triangle_motifs_internal, + }, + local_temporal_three_node_motifs::{ + temporal_three_node_motif as local_temporal_three_node_motif, + triangle_motifs as local_triangle_motifs_internal, + }, local_triangle_count::local_triangle_count, + three_node_motifs::{ + init_star_count, init_tri_count, init_two_node_count, new_triangle_edge, + star_event, two_node_event, + }, + temporal_rich_club_coefficient::temporal_rich_club_coefficient, + triangle_count::triangle_count, + triplet_count::triplet_count, }, + pathing::{ + dijkstra::dijkstra_single_source_shortest_paths, + single_source_shortest_path::single_source_shortest_path, + temporal_reachability::temporally_reachable_nodes, + }, + projections::temporal_bipartite_projection::temporal_bipartite_projection, }, + db::graph::views::filter::Unfiltered, graphgen::random_attachment::random_attachment, prelude::*, }; +use raphtory_api::core::Direction; use raphtory_benchmark::common::bench; -use rayon::prelude::*; use std::hint::black_box; +fn graph_benchmark_with_setup( + c: &mut Criterion, + name: &str, + measurement_secs: u64, + sample_size: usize, + build_graph: BuildGraph, + setup: Setup, + mut run: Run, +) where + BuildGraph: FnOnce() -> Graph, + Setup: FnOnce(&Graph) -> SetupData, + Run: FnMut(&Graph, &SetupData) -> Output, +{ + let mut group = c.benchmark_group(name); + let graph = build_graph(); + let setup_data = setup(&graph); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(measurement_secs)); + group.sample_size(sample_size); + group.bench_with_input(BenchmarkId::new(name, &graph), &graph, |b, graph| { + b.iter(|| { + let result = run(graph, &setup_data); + black_box(result); + }); + }); + group.finish() +} + +fn graph_benchmark( + c: &mut Criterion, + name: &str, + measurement_secs: u64, + sample_size: usize, + build_graph: BuildGraph, + run: Run, +) where + BuildGraph: FnOnce() -> Graph, + Run: FnMut(&Graph, &()) -> Output, +{ + graph_benchmark_with_setup(c, name, measurement_secs, sample_size, build_graph, |_| (), run) +} + +fn simple_benchmark( + c: &mut Criterion, + name: &str, + measurement_secs: u64, + sample_size: usize, + mut run: Run, +) where + Run: FnMut() -> Output, +{ + let mut group = c.benchmark_group(name); + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(measurement_secs)); + group.sample_size(sample_size); + group.bench_function(name, |b| { + b.iter(|| { + let result = run(); + black_box(result); + }); + }); + group.finish() +} + +fn large_random_attachment_graph() -> Graph { + let graph = Graph::new(); + let seed: [u8; 32] = [1; 32]; + random_attachment(&graph, 500000, 4, Some(seed)); + graph +} + +fn first_node_id(graph: &Graph) -> GID { + graph + .nodes() + .id() + .iter_values() + .next() + .expect("graph has nodes") +} + +fn large_weighted_random_attachment_graph() -> Graph { + let graph = large_random_attachment_graph(); + let ids = graph.nodes().id().iter_values().collect::>(); + if let (Some(src), Some(dst)) = (ids.first(), ids.get(1)) { + graph + .add_edge(0, src.clone(), dst.clone(), [("weight", 1.0f64)], None) + .expect("unable to add weighted edge"); + } + graph +} + +fn large_typed_random_attachment_graph() -> Graph { + let graph = large_random_attachment_graph(); + for id in graph.nodes().id().iter_values() { + graph + .add_node(0, id, NO_PROPS, Some("Right"), None) + .expect("unable to set node type"); + } + graph +} + pub fn local_triangle_count_analysis(c: &mut Criterion) { let mut group = c.benchmark_group("local_triangle_count"); group.sample_size(10); bench(&mut group, "local_triangle_count", None, |b| { - let g = raphtory::graph_loader::lotr_graph::lotr_graph(); - let windowed_graph = g.window(i64::MIN, i64::MAX); - - b.iter(|| { - let node_ids = windowed_graph.nodes().id().collect::>(); + let graph = large_random_attachment_graph(); + let node_id = graph.nodes().id().iter_values().next().expect("graph has nodes"); - node_ids.into_par_iter().for_each(|v| { - local_triangle_count(&windowed_graph, v).unwrap(); - }); - }) + b.iter(|| black_box(local_triangle_count(&graph, node_id.clone()).unwrap())) }); group.finish(); @@ -42,32 +191,84 @@ pub fn local_clustering_coefficient_analysis(c: &mut Criterion) { let mut group = c.benchmark_group("local_clustering_coefficient"); bench(&mut group, "local_clustering_coefficient", None, |b| { - let g: Graph = raphtory::graph_loader::lotr_graph::lotr_graph(); + let graph = large_random_attachment_graph(); + let node_id = graph.nodes().id().iter_values().next().expect("graph has nodes"); - b.iter(|| local_clustering_coefficient(&g, "Gandalf")) + b.iter(|| black_box(local_clustering_coefficient(&graph, node_id.clone()))) }); group.finish(); } +pub fn graphgen_large_clustering_coeff(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_clustering_coeff", + 60, + 10, + large_random_attachment_graph, + |graph, _| global_clustering_coefficient(graph), + ) +} +pub fn graphgen_large_pagerank(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_pagerank", + 20, + 10, + large_random_attachment_graph, + |graph, _| page_rank(graph, None, Some(100), None, None, true, None), + ) +} -pub fn graphgen_large_clustering_coeff(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_clustering_coeff"); - // generate graph - let graph = Graph::new(); - let seed: [u8; 32] = [1; 32]; - random_attachment(&graph, 500000, 4, Some(seed)); +pub fn graphgen_large_new_pagerank(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_new_pagerank", + 20, + 10, + large_random_attachment_graph, + |graph, _| new_page_rank(graph, None, Some(100), None, None, true, None), + ) +} + + +pub fn graphgen_large_concomp(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_concomp", + 60, + 10, + large_random_attachment_graph, + |graph, _| weakly_connected_components(graph), + ) +} + +pub fn graphgen_large_hits(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_hits", + 20, + 10, + large_random_attachment_graph, + |graph, _| hits(graph, 100, None), + ) +} + +pub fn graphgen_large_degree_centrality(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_degree_centrality"); + let graph = large_random_attachment_graph(); group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(60)); + group.measurement_time(std::time::Duration::from_secs(20)); group.sample_size(10); group.bench_with_input( - BenchmarkId::new("graphgen_large_clustering_coeff", &graph), + BenchmarkId::new("graphgen_large_degree_centrality", &graph), &graph, |b, graph| { b.iter(|| { - let result = global_clustering_coefficient(graph); + let result = degree_centrality(graph); black_box(result); }); }, @@ -75,22 +276,19 @@ pub fn graphgen_large_clustering_coeff(c: &mut Criterion) { group.finish() } -pub fn graphgen_large_pagerank(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_pagerank"); - // generate graph - let graph = Graph::new(); - let seed: [u8; 32] = [1; 32]; - random_attachment(&graph, 500000, 4, Some(seed)); +pub fn graphgen_large_betweenness(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_betweenness"); + let graph = large_random_attachment_graph(); group.sampling_mode(SamplingMode::Flat); group.measurement_time(std::time::Duration::from_secs(20)); group.sample_size(10); group.bench_with_input( - BenchmarkId::new("graphgen_large_pagerank", &graph), + BenchmarkId::new("graphgen_large_betweenness", &graph), &graph, |b, graph| { b.iter(|| { - let result = page_rank(graph, None, Some(100), None, None, true, None); + let result = betweenness_centrality(graph, None, false); black_box(result); }); }, @@ -98,22 +296,854 @@ pub fn graphgen_large_pagerank(c: &mut Criterion) { group.finish() } -pub fn graphgen_large_concomp(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_concomp"); - // generate graph - let graph = Graph::new(); - let seed: [u8; 32] = [1; 32]; - random_attachment(&graph, 500000, 4, Some(seed)); +pub fn graphgen_large_triangle_count(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_triangle_count"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_triangle_count", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = triangle_count(graph, None); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_triplet_count(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_triplet_count"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_triplet_count", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = triplet_count(graph, None); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_directed_density(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_directed_density"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_directed_density", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = directed_graph_density(graph); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_reciprocity(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_reciprocity"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_reciprocity", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = global_reciprocity(graph); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_scc(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_scc"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_scc", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = strongly_connected_components(graph); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_in_components(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_in_components"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_in_components", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = in_components(graph, None); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_out_components(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_out_components"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_out_components", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = out_components(graph, None); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_in_components_filtered(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_in_components_filtered"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_in_components_filtered", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = in_components_filtered(graph, None, Unfiltered).unwrap(); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_out_components_filtered(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_out_components_filtered"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_out_components_filtered", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = out_components_filtered(graph, None, Unfiltered).unwrap(); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_label_propagation(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_label_propagation"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_label_propagation", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = label_propagation(graph, 20, Some([1; 32]), None); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_louvain(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_louvain"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_louvain", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = louvain::(graph, 1.0, None, None); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_alternating_mask(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_alternating_mask"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_alternating_mask", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = alternating_mask(graph); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_all_local_reciprocity(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_all_local_reciprocity"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_all_local_reciprocity", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = all_local_reciprocity(graph); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_balance(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_balance", + 20, + 10, + large_weighted_random_attachment_graph, + |graph, _| balance(graph, "weight".to_string(), Direction::BOTH).unwrap(), + ) +} + +pub fn graphgen_large_max_degree(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_max_degree"); + let graph = large_random_attachment_graph(); group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(60)); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_max_degree", &graph), + &graph, + |b, graph| { + b.iter(|| black_box(max_degree(graph))); + }, + ); + group.finish() +} + +pub fn graphgen_large_min_degree(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_min_degree"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_min_degree", &graph), + &graph, + |b, graph| { + b.iter(|| black_box(min_degree(graph))); + }, + ); + group.finish() +} + +pub fn graphgen_large_max_out_degree(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_max_out_degree"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_max_out_degree", &graph), + &graph, + |b, graph| { + b.iter(|| black_box(max_out_degree(graph))); + }, + ); + group.finish() +} + +pub fn graphgen_large_max_in_degree(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_max_in_degree"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_max_in_degree", &graph), + &graph, + |b, graph| { + b.iter(|| black_box(max_in_degree(graph))); + }, + ); + group.finish() +} + +pub fn graphgen_large_min_out_degree(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_min_out_degree"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_min_out_degree", &graph), + &graph, + |b, graph| { + b.iter(|| black_box(min_out_degree(graph))); + }, + ); + group.finish() +} + +pub fn graphgen_large_min_in_degree(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_min_in_degree"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_min_in_degree", &graph), + &graph, + |b, graph| { + b.iter(|| black_box(min_in_degree(graph))); + }, + ); + group.finish() +} + +pub fn graphgen_large_average_degree(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_average_degree"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_average_degree", &graph), + &graph, + |b, graph| { + b.iter(|| black_box(average_degree(graph))); + }, + ); + group.finish() +} + +pub fn graphgen_large_local_clustering_coefficient_batch(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_local_clustering_coefficient_batch"); + let graph = large_random_attachment_graph(); + let node_id = first_node_id(&graph); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_local_clustering_coefficient_batch", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = local_clustering_coefficient_batch(graph, vec![node_id.clone()]); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_temporal_rich_club(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_temporal_rich_club"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_temporal_rich_club", &graph), + &graph, + |b, graph| { + b.iter(|| { + let rolling = graph.rolling(1, Some(1)).unwrap(); + let result = temporal_rich_club_coefficient(graph, rolling, 3, 3); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_temporal_motif_multi(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_temporal_motif_multi"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_temporal_motif_multi", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = temporal_three_node_motif_multi(graph, vec![100], None); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_local_temporal_motif(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_local_temporal_motif"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_local_temporal_motif", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = local_temporal_three_node_motif(graph, 100, None); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_dijkstra(c: &mut Criterion) { + graph_benchmark_with_setup( + c, + "graphgen_large_dijkstra", + 20, + 10, + large_random_attachment_graph, + first_node_id, + |graph, source| { + dijkstra_single_source_shortest_paths( + graph, + source.clone(), + vec![source.clone()], + None, + Direction::BOTH, + ) + .unwrap() + }, + ) +} + +pub fn graphgen_large_single_source_shortest_path(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_single_source_shortest_path"); + let graph = large_random_attachment_graph(); + let source = first_node_id(&graph); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_single_source_shortest_path", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = single_source_shortest_path(graph, source.clone(), None); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_temporally_reachable_nodes(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_temporally_reachable_nodes"); + let graph = large_random_attachment_graph(); + let source = first_node_id(&graph); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_temporally_reachable_nodes", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = + temporally_reachable_nodes(graph, None, 20, 0, vec![source.clone()], None); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_in_component(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_in_component"); + let graph = large_random_attachment_graph(); + let source = first_node_id(&graph); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_in_component", &graph), + &graph, + |b, graph| { + b.iter(|| { + let node = graph.node(source.clone()).expect("source node exists"); + let result = in_component(node); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_out_component(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_out_component"); + let graph = large_random_attachment_graph(); + let source = first_node_id(&graph); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_out_component", &graph), + &graph, + |b, graph| { + b.iter(|| { + let node = graph.node(source.clone()).expect("source node exists"); + let result = out_component(node); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_in_component_filtered(c: &mut Criterion) { + graph_benchmark_with_setup( + c, + "graphgen_large_in_component_filtered", + 20, + 10, + large_random_attachment_graph, + first_node_id, + |graph, source| { + let node = graph.node(source.clone()).expect("source node exists"); + in_component_filtered(node, Unfiltered).unwrap() + }, + ) +} + +pub fn graphgen_large_out_component_filtered(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_out_component_filtered"); + let graph = large_random_attachment_graph(); + let source = first_node_id(&graph); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_out_component_filtered", &graph), + &graph, + |b, graph| { + b.iter(|| { + let node = graph.node(source.clone()).expect("source node exists"); + let result = out_component_filtered(node, Unfiltered).unwrap(); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_internal_two_node_event(c: &mut Criterion) { + simple_benchmark(c, "graphgen_internal_two_node_event", 20, 10, || { + two_node_event(1, 100) + }) +} + +pub fn graphgen_internal_init_two_node_count(c: &mut Criterion) { + simple_benchmark(c, "graphgen_internal_init_two_node_count", 20, 10, || { + init_two_node_count() + }) +} + +pub fn graphgen_internal_star_event(c: &mut Criterion) { + simple_benchmark(c, "graphgen_internal_star_event", 20, 10, || { + star_event(0, 1, 100) + }) +} + +pub fn graphgen_internal_init_star_count(c: &mut Criterion) { + simple_benchmark(c, "graphgen_internal_init_star_count", 20, 10, || { + init_star_count(128) + }) +} + +pub fn graphgen_internal_new_triangle_edge(c: &mut Criterion) { + simple_benchmark(c, "graphgen_internal_new_triangle_edge", 20, 10, || { + new_triangle_edge(true, 1, 0, 1, 100) + }) +} + +pub fn graphgen_internal_init_tri_count(c: &mut Criterion) { + simple_benchmark(c, "graphgen_internal_init_tri_count", 20, 10, || { + init_tri_count(128) + }) +} + +pub fn graphgen_internal_global_triangle_motifs(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_internal_global_triangle_motifs"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_internal_global_triangle_motifs", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = global_triangle_motifs_internal(graph, vec![100], None); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_internal_local_triangle_motifs(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_internal_local_triangle_motifs"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_internal_local_triangle_motifs", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = local_triangle_motifs_internal(graph, vec![100], None); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_k_core_set(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_k_core_set"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_k_core_set", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = k_core_set(graph, 2, usize::MAX, None); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_k_core(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_k_core"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_k_core", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = k_core(graph, 2, usize::MAX, None); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_fruchterman_reingold(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_fruchterman_reingold"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_fruchterman_reingold", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = fruchterman_reingold_unbounded(graph, 5, 1.0, 1.0, 0.9, 0.1); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_cohesive_fruchterman_reingold(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_cohesive_fruchterman_reingold"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_cohesive_fruchterman_reingold", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = cohesive_fruchterman_reingold(graph, 5, 1.0, 1.0, 0.9, 0.1); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_fast_rp(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_fast_rp"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_fast_rp", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = fast_rp(graph, 32, 0.5, vec![1.0, 1.0, 1.0], Some(1), None); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_max_weight_matching(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_max_weight_matching"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_max_weight_matching", &graph), + &graph, + |b, graph| { + b.iter(|| { + let result = max_weight_matching(graph, None, false, false); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_temporal_seir(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_temporal_seir"); + let graph = large_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); + group.sample_size(10); + group.bench_with_input( + BenchmarkId::new("graphgen_large_temporal_seir", &graph), + &graph, + |b, graph| { + b.iter(|| { + let mut rng = SmallRng::seed_from_u64(1); + let result = temporal_SEIR(graph, Some(0.1), None, 0.5f64, 0, Number(1), &mut rng) + .unwrap(); + black_box(result); + }); + }, + ); + group.finish() +} + +pub fn graphgen_large_temporal_bipartite_projection(c: &mut Criterion) { + let mut group = c.benchmark_group("graphgen_large_temporal_bipartite_projection"); + let graph = large_typed_random_attachment_graph(); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(20)); group.sample_size(10); group.bench_with_input( - BenchmarkId::new("graphgen_large_concomp", &graph), + BenchmarkId::new("graphgen_large_temporal_bipartite_projection", &graph), &graph, |b, graph| { b.iter(|| { - let result = weakly_connected_components(graph); + let result = temporal_bipartite_projection(graph, 1, "Right".to_string()); black_box(result); }); }, @@ -125,9 +1155,9 @@ pub fn temporal_motifs(c: &mut Criterion) { let mut group = c.benchmark_group("temporal_motifs"); bench(&mut group, "temporal_motifs", None, |b| { - let g: Graph = raphtory::graph_loader::lotr_graph::lotr_graph(); + let graph = large_random_attachment_graph(); - b.iter(|| global_temporal_three_node_motif(&g, 100, None)) + b.iter(|| black_box(global_temporal_three_node_motif(&graph, 100, None))) }); group.finish(); @@ -139,7 +1169,59 @@ criterion_group!( local_clustering_coefficient_analysis, graphgen_large_clustering_coeff, graphgen_large_pagerank, + graphgen_large_new_pagerank, graphgen_large_concomp, + graphgen_large_hits, + graphgen_large_degree_centrality, + graphgen_large_betweenness, + graphgen_large_triangle_count, + graphgen_large_triplet_count, + graphgen_large_directed_density, + graphgen_large_reciprocity, + graphgen_large_scc, + graphgen_large_in_components, + graphgen_large_out_components, + graphgen_large_in_components_filtered, + graphgen_large_out_components_filtered, + graphgen_large_label_propagation, + graphgen_large_louvain, + graphgen_large_alternating_mask, + graphgen_large_all_local_reciprocity, + graphgen_large_balance, + graphgen_large_max_degree, + graphgen_large_min_degree, + graphgen_large_max_out_degree, + graphgen_large_max_in_degree, + graphgen_large_min_out_degree, + graphgen_large_min_in_degree, + graphgen_large_average_degree, + graphgen_large_local_clustering_coefficient_batch, + graphgen_large_temporal_rich_club, + graphgen_large_temporal_motif_multi, + graphgen_large_local_temporal_motif, + graphgen_large_dijkstra, + graphgen_large_single_source_shortest_path, + graphgen_large_temporally_reachable_nodes, + graphgen_large_in_component, + graphgen_large_out_component, + graphgen_large_in_component_filtered, + graphgen_large_out_component_filtered, + graphgen_large_k_core_set, + graphgen_large_k_core, + graphgen_large_fruchterman_reingold, + graphgen_large_cohesive_fruchterman_reingold, + graphgen_large_fast_rp, + graphgen_large_max_weight_matching, + graphgen_large_temporal_seir, + graphgen_large_temporal_bipartite_projection, + graphgen_internal_two_node_event, + graphgen_internal_init_two_node_count, + graphgen_internal_star_event, + graphgen_internal_init_star_count, + graphgen_internal_new_triangle_edge, + graphgen_internal_init_tri_count, + graphgen_internal_global_triangle_motifs, + graphgen_internal_local_triangle_motifs, temporal_motifs, ); criterion_main!(benches); diff --git a/raphtory/src/algorithms/centrality/mod.rs b/raphtory/src/algorithms/centrality/mod.rs index dc87e2bfeb..64fce608c6 100644 --- a/raphtory/src/algorithms/centrality/mod.rs +++ b/raphtory/src/algorithms/centrality/mod.rs @@ -2,4 +2,3 @@ pub mod betweenness; pub mod degree_centrality; pub mod hits; pub mod pagerank; -pub mod new_pagerank; diff --git a/raphtory/src/algorithms/centrality/new_pagerank.rs b/raphtory/src/algorithms/centrality/new_pagerank.rs deleted file mode 100644 index 05ebcf8bb3..0000000000 --- a/raphtory/src/algorithms/centrality/new_pagerank.rs +++ /dev/null @@ -1,260 +0,0 @@ -use crate::{ - core::state::{accumulator_id::accumulators, compute_state::ComputeStateVec}, - db::{ - api::{ - state::{GenericNodeState, TypedNodeState}, - view::{EdgeViewOps, NodeViewOps, StaticGraphViewOps, filter_ops::NodeSelect}, - }, graph::views::node_subgraph::NodeSubgraph, task::{ - context::Context, - task::{ATask, Job, Step}, - task_runner::TaskRunner, - } - }, - prelude::{GraphViewOps, PropertiesOps}, -}; -use num_traits::abs; -use raphtory_api::core::entities::properties::prop::PropUnwrap; -use serde::{Deserialize, Serialize}; -use crate::prelude::NodeFilter; -use crate::db::graph::views::filter::model::degree_filter::DegreeFilterFactory; -use crate::db::graph::views::filter::model::property_filter::ops::PropertyFilterOps; -use std::collections::HashMap; -use raphtory_api::core::entities::VID; - -#[derive(Clone, PartialEq, Serialize, Deserialize, Debug, Default)] -pub struct PageRankState { - #[serde(rename = "pagerank_score")] - pub score: f64, - #[serde(skip)] - weighted_out_degree: f64, - special_neighbor_weight: f64, - special_node_score: f64, - special_node_sink_contributor_count: usize, -} - -impl PageRankState { - fn new(num_nodes: usize) -> Self { - Self { - score: 1f64 / num_nodes as f64, - special_node_score: 1f64 / num_nodes as f64, - weighted_out_degree: 0f64, - special_neighbor_weight: 0.0, - special_node_sink_contributor_count: 0, - } - } - - fn reset(&mut self) { - self.score = 0f64; - self.special_node_score = 0f64; - } -} - -/// PageRank Algorithm: -/// PageRank shows how important a node is in a graph. -/// -/// # Arguments -/// -/// - `g`: A GraphView object -/// - `weight`: Edge property key to use as weight. If None, all edges have weight 1.0. -/// - `iter_count`: Number of iterations to run the algorithm for -/// - `threads`: Number of threads to use for parallel execution -/// - `tol`: The tolerance value for convergence -/// - `use_l2_norm`: Whether to use L2 norm for convergence -/// - `damping_factor`: Probability of likelihood the spread will continue -/// -/// # Returns -/// -/// An [AlgorithmResult] object containing the mapping from node ID to the PageRank score of the node -/// -pub fn page_rank( - g: &G, - weight: Option<&str>, - iter_count: Option, - threads: Option, - tol: Option, - use_l2_norm: bool, - damping_factor: Option, -) -> TypedNodeState<'static, PageRankState, NodeSubgraph> { - let n = g.count_nodes(); - let not_special_neighbors = g.nodes().select(NodeFilter.in_degree().eq(0)).unwrap(); - let f_g = g.subgraph(not_special_neighbors); - - let mut ctx: Context = g.into(); - - let tol: f64 = tol.unwrap_or(0.000001f64); - let damp = damping_factor.unwrap_or(0.85); - let iter_count = iter_count.unwrap_or(20); - let teleport_prob = (1f64 - damp) / n as f64; - let factor = damp / n as f64; - - let max_diff = accumulators::sum::(2); - - let total_sink_contribution = accumulators::sum::(4); - - - ctx.global_agg_reset(max_diff); - - ctx.global_agg_reset(total_sink_contribution); - - let weight_id = weight.and_then(|key| g.edge_meta().get_prop_id(key, false)); - - let mut special_node_sink_contributor_count = 0; - let mut special_node_out_degrees: HashMap = HashMap::new(); - for node in g.nodes() { - if node.in_degree() == 0 { - let weighted_out_degree = node.out_edges().iter().fold(0.0f64, |acc, edge| { - weight_id - .and_then(|id| edge.properties().get_by_id(id)) - .and_then(|p| p.as_f64()) - .unwrap_or(1.0) - + acc - }); - if (weighted_out_degree.abs() < f64::EPSILON) { - special_node_sink_contributor_count += 1; - } - special_node_out_degrees.insert(node.node, weighted_out_degree); - } - } - - - let step1 = ATask::new({ - move |s| { - let s_node = g.node(&s.node).unwrap(); - let weighted_out_degree = s_node.out_edges().iter().fold(0.0f64, |acc, edge| { - weight_id - .and_then(|id| edge.properties().get_by_id(id)) - .and_then(|p| p.as_f64()) - .unwrap_or(1.0) - + acc - }); - let state: &mut PageRankState = s.get_mut(); - state.weighted_out_degree = weighted_out_degree; - let special_neighbor_weight = s_node.in_edges().iter().fold(0.0f64, |acc, edge| { - let nbr = edge.nbr(); - if let Some(&weighted_out_degree) = special_node_out_degrees.get(&nbr.node) { - if weighted_out_degree > 0.0 { - let w = weight_id - .and_then(|id| edge.properties().get_by_id(id)) - .and_then(|p| p.as_f64()) - .unwrap_or(1.0); - acc + w / weighted_out_degree - } else { - acc - } - } else { - acc - } - }); - state.special_neighbor_weight = special_neighbor_weight; - Step::Continue - } - }); - - let step2: ATask = ATask::new(move |s| { - // reset score - { - let state: &mut PageRankState = s.get_mut(); - state.reset(); - } - - let special_node_score = s.prev().special_node_score; - - for edge in s.in_edges() { - let w = weight_id - .and_then(|id| edge.properties().get_by_id(id)) - .and_then(|p| p.as_f64()) - .unwrap_or(1.0); - let nbr = edge.nbr(); - let prev = nbr.prev(); - - if prev.weighted_out_degree > 0.0 { - s.get_mut().score += prev.score * w / prev.weighted_out_degree; - } - } - s.get_mut().score += s.prev().special_neighbor_weight * special_node_score; - - s.get_mut().score *= damp; - - s.get_mut().score += teleport_prob; - - s.get_mut().special_node_score *= damp; - - s.get_mut().special_node_score += teleport_prob; - Step::Continue - }); - - let step3 = ATask::new(move |s| { - let state: &mut PageRankState = s.get_mut(); - - if state.weighted_out_degree.abs() < f64::EPSILON { - let curr = s.prev().score; - - let ts_contrib = factor * curr; - s.global_update(&total_sink_contribution, ts_contrib); - } - Step::Continue - }); - - let step4 = ATask::new(move |s| { - //read total sink contribution - let total_sink_contribution = s - .read_global_state(&total_sink_contribution) - .unwrap_or_default(); - // update local score with total sink contribution - let total_sink_contribution = total_sink_contribution + s.prev().special_node_sink_contributor_count as f64 * factor * s.prev().special_node_score; - let state: &mut PageRankState = s.get_mut(); - state.score += total_sink_contribution; - state.special_node_score += total_sink_contribution; - - // update global max diff - - let curr = state.score; - let prev = s.prev().score; - - let md = if use_l2_norm { - f64::powi(abs(prev - curr), 2) - } else { - abs(prev - curr) - }; - - s.global_update(&max_diff, md); - Step::Continue - }); - - let step5 = Job::Check(Box::new(move |state| { - let max_diff_val = state.read(&max_diff); - let cont = if use_l2_norm { - let sum_d = f64::sqrt(max_diff_val); - (sum_d) > tol * n as f64 - } else { - (max_diff_val) > tol * n as f64 - }; - if cont { - Step::Continue - } else { - Step::Done - } - })); - - let mut runner: TaskRunner = TaskRunner::new(ctx); - - let num_nodes = g.count_nodes(); - - runner.run( - vec![Job::new(step1)], - vec![Job::new(step2), Job::new(step3), Job::new(step4), step5], - Some(vec![PageRankState::new(num_nodes); num_nodes]), - |_, _, _, local, index| { - TypedNodeState::new(GenericNodeState::new_from_eval_with_index( - f_g.clone(), - local, - index, - None, - )) - }, - threads, - iter_count, - None, - None, - ) -} From a7600288e999c22329ce3edbe049c173d7dea302 Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Thu, 18 Jun 2026 15:17:32 -0500 Subject: [PATCH 07/24] working --- raphtory-benchmark/benches/algobench.rs | 1099 ++++++++--------------- 1 file changed, 371 insertions(+), 728 deletions(-) diff --git a/raphtory-benchmark/benches/algobench.rs b/raphtory-benchmark/benches/algobench.rs index 91b0cb5893..0a01649268 100644 --- a/raphtory-benchmark/benches/algobench.rs +++ b/raphtory-benchmark/benches/algobench.rs @@ -6,7 +6,7 @@ use raphtory::{ bipartite::max_weight_matching::max_weight_matching, centrality::{ betweenness::betweenness_centrality, degree_centrality::degree_centrality, - hits::hits, new_pagerank::page_rank as new_page_rank, pagerank::page_rank, + hits::hits, pagerank::page_rank, }, community_detection::{ label_propagation::label_propagation, @@ -69,7 +69,6 @@ use raphtory::{ prelude::*, }; use raphtory_api::core::Direction; -use raphtory_benchmark::common::bench; use std::hint::black_box; fn graph_benchmark_with_setup( @@ -175,29 +174,27 @@ fn large_typed_random_attachment_graph() -> Graph { } pub fn local_triangle_count_analysis(c: &mut Criterion) { - let mut group = c.benchmark_group("local_triangle_count"); - group.sample_size(10); - bench(&mut group, "local_triangle_count", None, |b| { - let graph = large_random_attachment_graph(); - let node_id = graph.nodes().id().iter_values().next().expect("graph has nodes"); - - b.iter(|| black_box(local_triangle_count(&graph, node_id.clone()).unwrap())) - }); - - group.finish(); + graph_benchmark_with_setup( + c, + "local_triangle_count", + 20, + 10, + large_random_attachment_graph, + first_node_id, + |graph, node_id| local_triangle_count(graph, node_id.clone()).unwrap(), + ) } pub fn local_clustering_coefficient_analysis(c: &mut Criterion) { - let mut group = c.benchmark_group("local_clustering_coefficient"); - - bench(&mut group, "local_clustering_coefficient", None, |b| { - let graph = large_random_attachment_graph(); - let node_id = graph.nodes().id().iter_values().next().expect("graph has nodes"); - - b.iter(|| black_box(local_clustering_coefficient(&graph, node_id.clone()))) - }); - - group.finish(); + graph_benchmark_with_setup( + c, + "local_clustering_coefficient", + 20, + 10, + large_random_attachment_graph, + first_node_id, + |graph, node_id| local_clustering_coefficient(graph, node_id.clone()), + ) } pub fn graphgen_large_clustering_coeff(c: &mut Criterion) { @@ -222,18 +219,6 @@ pub fn graphgen_large_pagerank(c: &mut Criterion) { ) } -pub fn graphgen_large_new_pagerank(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_new_pagerank", - 20, - 10, - large_random_attachment_graph, - |graph, _| new_page_rank(graph, None, Some(100), None, None, true, None), - ) -} - - pub fn graphgen_large_concomp(c: &mut Criterion) { graph_benchmark( c, @@ -257,303 +242,168 @@ pub fn graphgen_large_hits(c: &mut Criterion) { } pub fn graphgen_large_degree_centrality(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_degree_centrality"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_degree_centrality", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = degree_centrality(graph); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_degree_centrality", + 20, + 10, + large_random_attachment_graph, + |graph, _| degree_centrality(graph), + ) } pub fn graphgen_large_betweenness(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_betweenness"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_betweenness", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = betweenness_centrality(graph, None, false); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_betweenness", + 20, + 10, + large_random_attachment_graph, + |graph, _| betweenness_centrality(graph, None, false), + ) } pub fn graphgen_large_triangle_count(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_triangle_count"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_triangle_count", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = triangle_count(graph, None); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_triangle_count", + 20, + 10, + large_random_attachment_graph, + |graph, _| triangle_count(graph, None), + ) } pub fn graphgen_large_triplet_count(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_triplet_count"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_triplet_count", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = triplet_count(graph, None); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_triplet_count", + 20, + 10, + large_random_attachment_graph, + |graph, _| triplet_count(graph, None), + ) } pub fn graphgen_large_directed_density(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_directed_density"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_directed_density", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = directed_graph_density(graph); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_directed_density", + 20, + 10, + large_random_attachment_graph, + |graph, _| directed_graph_density(graph), + ) } pub fn graphgen_large_reciprocity(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_reciprocity"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_reciprocity", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = global_reciprocity(graph); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_reciprocity", + 20, + 10, + large_random_attachment_graph, + |graph, _| global_reciprocity(graph), + ) } pub fn graphgen_large_scc(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_scc"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_scc", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = strongly_connected_components(graph); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_scc", + 20, + 10, + large_random_attachment_graph, + |graph, _| strongly_connected_components(graph), + ) } pub fn graphgen_large_in_components(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_in_components"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_in_components", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = in_components(graph, None); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_in_components", + 20, + 10, + large_random_attachment_graph, + |graph, _| in_components(graph, None), + ) } pub fn graphgen_large_out_components(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_out_components"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_out_components", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = out_components(graph, None); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_out_components", + 20, + 10, + large_random_attachment_graph, + |graph, _| out_components(graph, None), + ) } pub fn graphgen_large_in_components_filtered(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_in_components_filtered"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_in_components_filtered", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = in_components_filtered(graph, None, Unfiltered).unwrap(); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_in_components_filtered", + 20, + 10, + large_random_attachment_graph, + |graph, _| in_components_filtered(graph, None, Unfiltered).unwrap(), + ) } pub fn graphgen_large_out_components_filtered(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_out_components_filtered"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_out_components_filtered", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = out_components_filtered(graph, None, Unfiltered).unwrap(); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_out_components_filtered", + 20, + 10, + large_random_attachment_graph, + |graph, _| out_components_filtered(graph, None, Unfiltered).unwrap(), + ) } pub fn graphgen_large_label_propagation(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_label_propagation"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_label_propagation", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = label_propagation(graph, 20, Some([1; 32]), None); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_label_propagation", + 20, + 10, + large_random_attachment_graph, + |graph, _| label_propagation(graph, 20, Some([1; 32]), None), + ) } pub fn graphgen_large_louvain(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_louvain"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_louvain", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = louvain::(graph, 1.0, None, None); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_louvain", + 20, + 10, + large_random_attachment_graph, + |graph, _| louvain::(graph, 1.0, None, None), + ) } pub fn graphgen_large_alternating_mask(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_alternating_mask"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_alternating_mask", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = alternating_mask(graph); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_alternating_mask", + 20, + 10, + large_random_attachment_graph, + |graph, _| alternating_mask(graph), + ) } pub fn graphgen_large_all_local_reciprocity(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_all_local_reciprocity"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_all_local_reciprocity", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = all_local_reciprocity(graph); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_all_local_reciprocity", + 20, + 10, + large_random_attachment_graph, + |graph, _| all_local_reciprocity(graph), + ) } pub fn graphgen_large_balance(c: &mut Criterion) { @@ -568,204 +418,128 @@ pub fn graphgen_large_balance(c: &mut Criterion) { } pub fn graphgen_large_max_degree(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_max_degree"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_max_degree", &graph), - &graph, - |b, graph| { - b.iter(|| black_box(max_degree(graph))); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_max_degree", + 20, + 10, + large_random_attachment_graph, + |graph, _| max_degree(graph), + ) } pub fn graphgen_large_min_degree(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_min_degree"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_min_degree", &graph), - &graph, - |b, graph| { - b.iter(|| black_box(min_degree(graph))); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_min_degree", + 20, + 10, + large_random_attachment_graph, + |graph, _| min_degree(graph), + ) } pub fn graphgen_large_max_out_degree(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_max_out_degree"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_max_out_degree", &graph), - &graph, - |b, graph| { - b.iter(|| black_box(max_out_degree(graph))); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_max_out_degree", + 20, + 10, + large_random_attachment_graph, + |graph, _| max_out_degree(graph), + ) } pub fn graphgen_large_max_in_degree(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_max_in_degree"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_max_in_degree", &graph), - &graph, - |b, graph| { - b.iter(|| black_box(max_in_degree(graph))); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_max_in_degree", + 20, + 10, + large_random_attachment_graph, + |graph, _| max_in_degree(graph), + ) } pub fn graphgen_large_min_out_degree(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_min_out_degree"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_min_out_degree", &graph), - &graph, - |b, graph| { - b.iter(|| black_box(min_out_degree(graph))); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_min_out_degree", + 20, + 10, + large_random_attachment_graph, + |graph, _| min_out_degree(graph), + ) } pub fn graphgen_large_min_in_degree(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_min_in_degree"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_min_in_degree", &graph), - &graph, - |b, graph| { - b.iter(|| black_box(min_in_degree(graph))); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_min_in_degree", + 20, + 10, + large_random_attachment_graph, + |graph, _| min_in_degree(graph), + ) } pub fn graphgen_large_average_degree(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_average_degree"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_average_degree", &graph), - &graph, - |b, graph| { - b.iter(|| black_box(average_degree(graph))); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_average_degree", + 20, + 10, + large_random_attachment_graph, + |graph, _| average_degree(graph), + ) } pub fn graphgen_large_local_clustering_coefficient_batch(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_local_clustering_coefficient_batch"); - let graph = large_random_attachment_graph(); - let node_id = first_node_id(&graph); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_local_clustering_coefficient_batch", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = local_clustering_coefficient_batch(graph, vec![node_id.clone()]); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark_with_setup( + c, + "graphgen_large_local_clustering_coefficient_batch", + 20, + 10, + large_random_attachment_graph, + first_node_id, + |graph, node_id| local_clustering_coefficient_batch(graph, vec![node_id.clone()]), + ) } pub fn graphgen_large_temporal_rich_club(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_temporal_rich_club"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_temporal_rich_club", &graph), - &graph, - |b, graph| { - b.iter(|| { - let rolling = graph.rolling(1, Some(1)).unwrap(); - let result = temporal_rich_club_coefficient(graph, rolling, 3, 3); - black_box(result); - }); + graph_benchmark( + c, + "graphgen_large_temporal_rich_club", + 20, + 10, + large_random_attachment_graph, + |graph, _| { + let rolling = graph.rolling(1, Some(1)).unwrap(); + temporal_rich_club_coefficient(graph, rolling, 3, 3) }, - ); - group.finish() + ) } pub fn graphgen_large_temporal_motif_multi(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_temporal_motif_multi"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_temporal_motif_multi", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = temporal_three_node_motif_multi(graph, vec![100], None); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_temporal_motif_multi", + 20, + 10, + large_random_attachment_graph, + |graph, _| temporal_three_node_motif_multi(graph, vec![100], None), + ) } pub fn graphgen_large_local_temporal_motif(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_local_temporal_motif"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_local_temporal_motif", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = local_temporal_three_node_motif(graph, 100, None); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_local_temporal_motif", + 20, + 10, + large_random_attachment_graph, + |graph, _| local_temporal_three_node_motif(graph, 100, None), + ) } pub fn graphgen_large_dijkstra(c: &mut Criterion) { @@ -790,90 +564,57 @@ pub fn graphgen_large_dijkstra(c: &mut Criterion) { } pub fn graphgen_large_single_source_shortest_path(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_single_source_shortest_path"); - let graph = large_random_attachment_graph(); - let source = first_node_id(&graph); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_single_source_shortest_path", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = single_source_shortest_path(graph, source.clone(), None); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark_with_setup( + c, + "graphgen_large_single_source_shortest_path", + 20, + 10, + large_random_attachment_graph, + first_node_id, + |graph, source| single_source_shortest_path(graph, source.clone(), None), + ) } pub fn graphgen_large_temporally_reachable_nodes(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_temporally_reachable_nodes"); - let graph = large_random_attachment_graph(); - let source = first_node_id(&graph); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_temporally_reachable_nodes", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = - temporally_reachable_nodes(graph, None, 20, 0, vec![source.clone()], None); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark_with_setup( + c, + "graphgen_large_temporally_reachable_nodes", + 20, + 10, + large_random_attachment_graph, + first_node_id, + |graph, source| temporally_reachable_nodes(graph, None, 20, 0, vec![source.clone()], None), + ) } pub fn graphgen_large_in_component(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_in_component"); - let graph = large_random_attachment_graph(); - let source = first_node_id(&graph); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_in_component", &graph), - &graph, - |b, graph| { - b.iter(|| { - let node = graph.node(source.clone()).expect("source node exists"); - let result = in_component(node); - black_box(result); - }); + graph_benchmark_with_setup( + c, + "graphgen_large_in_component", + 20, + 10, + large_random_attachment_graph, + first_node_id, + |graph, source| { + let node = graph.node(source.clone()).expect("source node exists"); + in_component(node) }, - ); - group.finish() + ) } pub fn graphgen_large_out_component(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_out_component"); - let graph = large_random_attachment_graph(); - let source = first_node_id(&graph); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_out_component", &graph), - &graph, - |b, graph| { - b.iter(|| { - let node = graph.node(source.clone()).expect("source node exists"); - let result = out_component(node); - black_box(result); - }); + graph_benchmark_with_setup( + c, + "graphgen_large_out_component", + 20, + 10, + large_random_attachment_graph, + first_node_id, + |graph, source| { + let node = graph.node(source.clone()).expect("source node exists"); + out_component(node) }, - ); - group.finish() + ) } pub fn graphgen_large_in_component_filtered(c: &mut Criterion) { @@ -892,25 +633,18 @@ pub fn graphgen_large_in_component_filtered(c: &mut Criterion) { } pub fn graphgen_large_out_component_filtered(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_out_component_filtered"); - let graph = large_random_attachment_graph(); - let source = first_node_id(&graph); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_out_component_filtered", &graph), - &graph, - |b, graph| { - b.iter(|| { - let node = graph.node(source.clone()).expect("source node exists"); - let result = out_component_filtered(node, Unfiltered).unwrap(); - black_box(result); - }); + graph_benchmark_with_setup( + c, + "graphgen_large_out_component_filtered", + 20, + 10, + large_random_attachment_graph, + first_node_id, + |graph, source| { + let node = graph.node(source.clone()).expect("source node exists"); + out_component_filtered(node, Unfiltered).unwrap() }, - ); - group.finish() + ) } pub fn graphgen_internal_two_node_event(c: &mut Criterion) { @@ -950,217 +684,127 @@ pub fn graphgen_internal_init_tri_count(c: &mut Criterion) { } pub fn graphgen_internal_global_triangle_motifs(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_internal_global_triangle_motifs"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_internal_global_triangle_motifs", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = global_triangle_motifs_internal(graph, vec![100], None); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_internal_global_triangle_motifs", + 20, + 10, + large_random_attachment_graph, + |graph, _| global_triangle_motifs_internal(graph, vec![100], None), + ) } pub fn graphgen_internal_local_triangle_motifs(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_internal_local_triangle_motifs"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_internal_local_triangle_motifs", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = local_triangle_motifs_internal(graph, vec![100], None); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_internal_local_triangle_motifs", + 20, + 10, + large_random_attachment_graph, + |graph, _| local_triangle_motifs_internal(graph, vec![100], None), + ) } pub fn graphgen_large_k_core_set(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_k_core_set"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_k_core_set", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = k_core_set(graph, 2, usize::MAX, None); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_k_core_set", + 20, + 10, + large_random_attachment_graph, + |graph, _| k_core_set(graph, 2, usize::MAX, None), + ) } pub fn graphgen_large_k_core(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_k_core"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_k_core", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = k_core(graph, 2, usize::MAX, None); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_k_core", + 20, + 10, + large_random_attachment_graph, + |graph, _| k_core(graph, 2, usize::MAX, None), + ) } pub fn graphgen_large_fruchterman_reingold(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_fruchterman_reingold"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_fruchterman_reingold", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = fruchterman_reingold_unbounded(graph, 5, 1.0, 1.0, 0.9, 0.1); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_fruchterman_reingold", + 20, + 10, + large_random_attachment_graph, + |graph, _| fruchterman_reingold_unbounded(graph, 5, 1.0, 1.0, 0.9, 0.1), + ) } pub fn graphgen_large_cohesive_fruchterman_reingold(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_cohesive_fruchterman_reingold"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_cohesive_fruchterman_reingold", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = cohesive_fruchterman_reingold(graph, 5, 1.0, 1.0, 0.9, 0.1); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_cohesive_fruchterman_reingold", + 20, + 10, + large_random_attachment_graph, + |graph, _| cohesive_fruchterman_reingold(graph, 5, 1.0, 1.0, 0.9, 0.1), + ) } pub fn graphgen_large_fast_rp(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_fast_rp"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_fast_rp", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = fast_rp(graph, 32, 0.5, vec![1.0, 1.0, 1.0], Some(1), None); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_fast_rp", + 20, + 10, + large_random_attachment_graph, + |graph, _| fast_rp(graph, 32, 0.5, vec![1.0, 1.0, 1.0], Some(1), None), + ) } pub fn graphgen_large_max_weight_matching(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_max_weight_matching"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_max_weight_matching", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = max_weight_matching(graph, None, false, false); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_max_weight_matching", + 20, + 10, + large_random_attachment_graph, + |graph, _| max_weight_matching(graph, None, false, false), + ) } pub fn graphgen_large_temporal_seir(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_temporal_seir"); - let graph = large_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_temporal_seir", &graph), - &graph, - |b, graph| { - b.iter(|| { - let mut rng = SmallRng::seed_from_u64(1); - let result = temporal_SEIR(graph, Some(0.1), None, 0.5f64, 0, Number(1), &mut rng) - .unwrap(); - black_box(result); - }); + graph_benchmark( + c, + "graphgen_large_temporal_seir", + 20, + 10, + large_random_attachment_graph, + |graph, _| { + let mut rng = SmallRng::seed_from_u64(1); + temporal_SEIR(graph, Some(0.1), None, 0.5f64, 0, Number(1), &mut rng).unwrap() }, - ); - group.finish() + ) } pub fn graphgen_large_temporal_bipartite_projection(c: &mut Criterion) { - let mut group = c.benchmark_group("graphgen_large_temporal_bipartite_projection"); - let graph = large_typed_random_attachment_graph(); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(20)); - group.sample_size(10); - group.bench_with_input( - BenchmarkId::new("graphgen_large_temporal_bipartite_projection", &graph), - &graph, - |b, graph| { - b.iter(|| { - let result = temporal_bipartite_projection(graph, 1, "Right".to_string()); - black_box(result); - }); - }, - ); - group.finish() + graph_benchmark( + c, + "graphgen_large_temporal_bipartite_projection", + 20, + 10, + large_typed_random_attachment_graph, + |graph, _| temporal_bipartite_projection(graph, 1, "Right".to_string()), + ) } pub fn temporal_motifs(c: &mut Criterion) { - let mut group = c.benchmark_group("temporal_motifs"); - - bench(&mut group, "temporal_motifs", None, |b| { - let graph = large_random_attachment_graph(); - - b.iter(|| black_box(global_temporal_three_node_motif(&graph, 100, None))) - }); - - group.finish(); + graph_benchmark( + c, + "temporal_motifs", + 20, + 10, + large_random_attachment_graph, + |graph, _| global_temporal_three_node_motif(graph, 100, None), + ) } criterion_group!( @@ -1169,7 +813,6 @@ criterion_group!( local_clustering_coefficient_analysis, graphgen_large_clustering_coeff, graphgen_large_pagerank, - graphgen_large_new_pagerank, graphgen_large_concomp, graphgen_large_hits, graphgen_large_degree_centrality, From b2a1977576e075960dd6887834f8cde2102e3d38 Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Thu, 18 Jun 2026 18:16:28 -0500 Subject: [PATCH 08/24] working --- raphtory-benchmark/benches/algobench.rs | 40 +++++++++++-------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/raphtory-benchmark/benches/algobench.rs b/raphtory-benchmark/benches/algobench.rs index 0a01649268..e3a740050e 100644 --- a/raphtory-benchmark/benches/algobench.rs +++ b/raphtory-benchmark/benches/algobench.rs @@ -1,4 +1,4 @@ -use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, SamplingMode}; +use criterion::{criterion_group, criterion_main, Criterion, SamplingMode}; use rand::{rngs::SmallRng, SeedableRng}; use raphtory::{ algorithms::{ @@ -19,7 +19,7 @@ use raphtory::{ strongly_connected_components, weakly_connected_components, }, cores::k_core::{k_core, k_core_set}, - dynamics::temporal::epidemics::{temporal_SEIR, Number}, + dynamics::temporal::epidemics::{Number, temporal_SEIR}, embeddings::fast_rp::fast_rp, layout::{ cohesive_fruchterman_reingold::cohesive_fruchterman_reingold, @@ -43,19 +43,13 @@ use raphtory::{ global_temporal_three_node_motifs::{ global_temporal_three_node_motif, temporal_three_node_motif_multi, triangle_motifs as global_triangle_motifs_internal, - }, - local_temporal_three_node_motifs::{ + }, local_temporal_three_node_motifs::{ temporal_three_node_motif as local_temporal_three_node_motif, triangle_motifs as local_triangle_motifs_internal, - }, - local_triangle_count::local_triangle_count, - three_node_motifs::{ + }, local_triangle_count::local_triangle_count, temporal_rich_club_coefficient::temporal_rich_club_coefficient, three_node_motifs::{ init_star_count, init_tri_count, init_two_node_count, new_triangle_edge, star_event, two_node_event, - }, - temporal_rich_club_coefficient::temporal_rich_club_coefficient, - triangle_count::triangle_count, - triplet_count::triplet_count, + }, triangle_count::triangle_count, triplet_count::triplet_count }, pathing::{ dijkstra::dijkstra_single_source_shortest_paths, @@ -64,14 +58,14 @@ use raphtory::{ }, projections::temporal_bipartite_projection::temporal_bipartite_projection, }, - db::graph::views::filter::Unfiltered, + db::{api::view::StaticGraphViewOps, graph::views::filter::Unfiltered}, graphgen::random_attachment::random_attachment, prelude::*, }; use raphtory_api::core::Direction; use std::hint::black_box; -fn graph_benchmark_with_setup( +fn graph_benchmark_with_setup( c: &mut Criterion, name: &str, measurement_secs: u64, @@ -80,9 +74,10 @@ fn graph_benchmark_with_setup( setup: Setup, mut run: Run, ) where - BuildGraph: FnOnce() -> Graph, - Setup: FnOnce(&Graph) -> SetupData, - Run: FnMut(&Graph, &SetupData) -> Output, + G: StaticGraphViewOps, + BuildGraph: FnOnce() -> G, + Setup: Fn(&G) -> SetupData, + Run: FnMut(&G, &SetupData) -> Output, { let mut group = c.benchmark_group(name); let graph = build_graph(); @@ -91,16 +86,16 @@ fn graph_benchmark_with_setup( group.sampling_mode(SamplingMode::Flat); group.measurement_time(std::time::Duration::from_secs(measurement_secs)); group.sample_size(sample_size); - group.bench_with_input(BenchmarkId::new(name, &graph), &graph, |b, graph| { + group.bench_function(name, |b| { b.iter(|| { - let result = run(graph, &setup_data); + let result = run(&graph, &setup_data); black_box(result); }); }); group.finish() } -fn graph_benchmark( +fn graph_benchmark( c: &mut Criterion, name: &str, measurement_secs: u64, @@ -108,8 +103,9 @@ fn graph_benchmark( build_graph: BuildGraph, run: Run, ) where - BuildGraph: FnOnce() -> Graph, - Run: FnMut(&Graph, &()) -> Output, + G: StaticGraphViewOps, + BuildGraph: FnOnce() -> G, + Run: FnMut(&G, &()) -> Output, { graph_benchmark_with_setup(c, name, measurement_secs, sample_size, build_graph, |_| (), run) } @@ -143,7 +139,7 @@ fn large_random_attachment_graph() -> Graph { graph } -fn first_node_id(graph: &Graph) -> GID { +fn first_node_id(graph: &G) -> GID { graph .nodes() .id() From c2bfd49b232a407852e1184b86fb424495f631ab Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Thu, 18 Jun 2026 20:51:31 -0500 Subject: [PATCH 09/24] working --- raphtory-benchmark/benches/algobench.rs | 946 +++++++++++++++++++++++- 1 file changed, 935 insertions(+), 11 deletions(-) diff --git a/raphtory-benchmark/benches/algobench.rs b/raphtory-benchmark/benches/algobench.rs index e3a740050e..116525b403 100644 --- a/raphtory-benchmark/benches/algobench.rs +++ b/raphtory-benchmark/benches/algobench.rs @@ -1,4 +1,4 @@ -use criterion::{criterion_group, criterion_main, Criterion, SamplingMode}; +use criterion::{criterion_group, criterion_main, Criterion, SamplingMode}; use rand::{rngs::SmallRng, SeedableRng}; use raphtory::{ algorithms::{ @@ -58,7 +58,7 @@ use raphtory::{ }, projections::temporal_bipartite_projection::temporal_bipartite_projection, }, - db::{api::view::StaticGraphViewOps, graph::views::filter::Unfiltered}, + db::{api::view::StaticGraphViewOps, graph::views::{filter::Unfiltered, node_subgraph::NodeSubgraph}}, graphgen::random_attachment::random_attachment, prelude::*, }; @@ -139,6 +139,12 @@ fn large_random_attachment_graph() -> Graph { graph } +fn large_random_attachment_subgraph() -> NodeSubgraph { + let graph = large_random_attachment_graph(); + let subgraph = graph.subgraph(graph.nodes()); + subgraph +} + fn first_node_id(graph: &G) -> GID { graph .nodes() @@ -159,6 +165,12 @@ fn large_weighted_random_attachment_graph() -> Graph { graph } +fn large_weighted_random_attachment_subgraph() -> NodeSubgraph { + let graph = large_weighted_random_attachment_graph(); + let subgraph = graph.subgraph(graph.nodes()); + subgraph +} + fn large_typed_random_attachment_graph() -> Graph { let graph = large_random_attachment_graph(); for id in graph.nodes().id().iter_values() { @@ -169,6 +181,27 @@ fn large_typed_random_attachment_graph() -> Graph { graph } +fn large_typed_random_attachment_subgraph() -> NodeSubgraph { + let graph = large_typed_random_attachment_graph(); + let subgraph = graph.subgraph(graph.nodes()); + subgraph +} + +fn large_random_attachment_layered() -> impl StaticGraphViewOps { + let graph = large_random_attachment_graph(); + graph.default_layer() +} + +fn large_weighted_random_attachment_layered() -> impl StaticGraphViewOps { + let graph = large_weighted_random_attachment_graph(); + graph.default_layer() +} + +fn large_typed_random_attachment_layered() -> impl StaticGraphViewOps { + let graph = large_typed_random_attachment_graph(); + graph.default_layer() +} + pub fn local_triangle_count_analysis(c: &mut Criterion) { graph_benchmark_with_setup( c, @@ -178,7 +211,26 @@ pub fn local_triangle_count_analysis(c: &mut Criterion) { large_random_attachment_graph, first_node_id, |graph, node_id| local_triangle_count(graph, node_id.clone()).unwrap(), - ) + ); + + graph_benchmark_with_setup( + c, + "local_triangle_count_subgraph", + 20, + 10, + large_random_attachment_subgraph, + first_node_id, + |graph, node_id| local_triangle_count(graph, node_id.clone()).unwrap(), + ); + graph_benchmark_with_setup( + c, + "local_triangle_count_layered", + 20, + 10, + large_random_attachment_layered, + first_node_id, + |graph, node_id| local_triangle_count(graph, node_id.clone()).unwrap(), + ); } pub fn local_clustering_coefficient_analysis(c: &mut Criterion) { @@ -190,6 +242,24 @@ pub fn local_clustering_coefficient_analysis(c: &mut Criterion) { large_random_attachment_graph, first_node_id, |graph, node_id| local_clustering_coefficient(graph, node_id.clone()), + ); + graph_benchmark_with_setup( + c, + "local_clustering_coefficient_subgraph", + 20, + 10, + large_random_attachment_subgraph, + first_node_id, + |graph, node_id| local_clustering_coefficient(graph, node_id.clone()), + ); + graph_benchmark_with_setup( + c, + "local_clustering_coefficient_layered", + 20, + 10, + large_random_attachment_layered, + first_node_id, + |graph, node_id| local_clustering_coefficient(graph, node_id.clone()), ) } @@ -201,6 +271,22 @@ pub fn graphgen_large_clustering_coeff(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| global_clustering_coefficient(graph), + ); + graph_benchmark( + c, + "graphgen_large_clustering_coeff_subgraph", + 60, + 10, + large_random_attachment_subgraph, + |graph, _| global_clustering_coefficient(graph), + ); + graph_benchmark( + c, + "graphgen_large_clustering_coeff_layered", + 60, + 10, + large_random_attachment_layered, + |graph, _| global_clustering_coefficient(graph), ) } @@ -212,6 +298,22 @@ pub fn graphgen_large_pagerank(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| page_rank(graph, None, Some(100), None, None, true, None), + ); + graph_benchmark( + c, + "graphgen_large_pagerank_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| page_rank(graph, None, Some(100), None, None, true, None), + ); + graph_benchmark( + c, + "graphgen_large_pagerank_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| page_rank(graph, None, Some(100), None, None, true, None), ) } @@ -223,6 +325,22 @@ pub fn graphgen_large_concomp(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| weakly_connected_components(graph), + ); + graph_benchmark( + c, + "graphgen_large_concomp_subgraph", + 60, + 10, + large_random_attachment_subgraph, + |graph, _| weakly_connected_components(graph), + ); + graph_benchmark( + c, + "graphgen_large_concomp_layered", + 60, + 10, + large_random_attachment_layered, + |graph, _| weakly_connected_components(graph), ) } @@ -234,6 +352,22 @@ pub fn graphgen_large_hits(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| hits(graph, 100, None), + ); + graph_benchmark( + c, + "graphgen_large_hits_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| hits(graph, 100, None), + ); + graph_benchmark( + c, + "graphgen_large_hits_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| hits(graph, 100, None), ) } @@ -245,6 +379,22 @@ pub fn graphgen_large_degree_centrality(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| degree_centrality(graph), + ); + graph_benchmark( + c, + "graphgen_large_degree_centrality_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| degree_centrality(graph), + ); + graph_benchmark( + c, + "graphgen_large_degree_centrality_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| degree_centrality(graph), ) } @@ -256,6 +406,22 @@ pub fn graphgen_large_betweenness(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| betweenness_centrality(graph, None, false), + ); + graph_benchmark( + c, + "graphgen_large_betweenness_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| betweenness_centrality(graph, None, false), + ); + graph_benchmark( + c, + "graphgen_large_betweenness_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| betweenness_centrality(graph, None, false), ) } @@ -267,6 +433,22 @@ pub fn graphgen_large_triangle_count(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| triangle_count(graph, None), + ); + graph_benchmark( + c, + "graphgen_large_triangle_count_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| triangle_count(graph, None), + ); + graph_benchmark( + c, + "graphgen_large_triangle_count_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| triangle_count(graph, None), ) } @@ -278,6 +460,22 @@ pub fn graphgen_large_triplet_count(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| triplet_count(graph, None), + ); + graph_benchmark( + c, + "graphgen_large_triplet_count_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| triplet_count(graph, None), + ); + graph_benchmark( + c, + "graphgen_large_triplet_count_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| triplet_count(graph, None), ) } @@ -289,6 +487,22 @@ pub fn graphgen_large_directed_density(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| directed_graph_density(graph), + ); + graph_benchmark( + c, + "graphgen_large_directed_density_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| directed_graph_density(graph), + ); + graph_benchmark( + c, + "graphgen_large_directed_density_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| directed_graph_density(graph), ) } @@ -300,6 +514,22 @@ pub fn graphgen_large_reciprocity(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| global_reciprocity(graph), + ); + graph_benchmark( + c, + "graphgen_large_reciprocity_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| global_reciprocity(graph), + ); + graph_benchmark( + c, + "graphgen_large_reciprocity_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| global_reciprocity(graph), ) } @@ -311,6 +541,22 @@ pub fn graphgen_large_scc(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| strongly_connected_components(graph), + ); + graph_benchmark( + c, + "graphgen_large_scc_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| strongly_connected_components(graph), + ); + graph_benchmark( + c, + "graphgen_large_scc_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| strongly_connected_components(graph), ) } @@ -322,6 +568,22 @@ pub fn graphgen_large_in_components(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| in_components(graph, None), + ); + graph_benchmark( + c, + "graphgen_large_in_components_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| in_components(graph, None), + ); + graph_benchmark( + c, + "graphgen_large_in_components_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| in_components(graph, None), ) } @@ -333,6 +595,22 @@ pub fn graphgen_large_out_components(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| out_components(graph, None), + ); + graph_benchmark( + c, + "graphgen_large_out_components_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| out_components(graph, None), + ); + graph_benchmark( + c, + "graphgen_large_out_components_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| out_components(graph, None), ) } @@ -344,6 +622,22 @@ pub fn graphgen_large_in_components_filtered(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| in_components_filtered(graph, None, Unfiltered).unwrap(), + ); + graph_benchmark( + c, + "graphgen_large_in_components_filtered_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| in_components_filtered(graph, None, Unfiltered).unwrap(), + ); + graph_benchmark( + c, + "graphgen_large_in_components_filtered_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| in_components_filtered(graph, None, Unfiltered).unwrap(), ) } @@ -355,6 +649,22 @@ pub fn graphgen_large_out_components_filtered(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| out_components_filtered(graph, None, Unfiltered).unwrap(), + ); + graph_benchmark( + c, + "graphgen_large_out_components_filtered_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| out_components_filtered(graph, None, Unfiltered).unwrap(), + ); + graph_benchmark( + c, + "graphgen_large_out_components_filtered_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| out_components_filtered(graph, None, Unfiltered).unwrap(), ) } @@ -366,6 +676,22 @@ pub fn graphgen_large_label_propagation(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| label_propagation(graph, 20, Some([1; 32]), None), + ); + graph_benchmark( + c, + "graphgen_large_label_propagation_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| label_propagation(graph, 20, Some([1; 32]), None), + ); + graph_benchmark( + c, + "graphgen_large_label_propagation_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| label_propagation(graph, 20, Some([1; 32]), None), ) } @@ -377,6 +703,22 @@ pub fn graphgen_large_louvain(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| louvain::(graph, 1.0, None, None), + ); + graph_benchmark( + c, + "graphgen_large_louvain_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| louvain::(graph, 1.0, None, None), + ); + graph_benchmark( + c, + "graphgen_large_louvain_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| louvain::(graph, 1.0, None, None), ) } @@ -388,6 +730,22 @@ pub fn graphgen_large_alternating_mask(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| alternating_mask(graph), + ); + graph_benchmark( + c, + "graphgen_large_alternating_mask_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| alternating_mask(graph), + ); + graph_benchmark( + c, + "graphgen_large_alternating_mask_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| alternating_mask(graph), ) } @@ -399,6 +757,22 @@ pub fn graphgen_large_all_local_reciprocity(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| all_local_reciprocity(graph), + ); + graph_benchmark( + c, + "graphgen_large_all_local_reciprocity_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| all_local_reciprocity(graph), + ); + graph_benchmark( + c, + "graphgen_large_all_local_reciprocity_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| all_local_reciprocity(graph), ) } @@ -410,6 +784,22 @@ pub fn graphgen_large_balance(c: &mut Criterion) { 10, large_weighted_random_attachment_graph, |graph, _| balance(graph, "weight".to_string(), Direction::BOTH).unwrap(), + ); + graph_benchmark( + c, + "graphgen_large_balance_subgraph", + 20, + 10, + large_weighted_random_attachment_subgraph, + |graph, _| balance(graph, "weight".to_string(), Direction::BOTH).unwrap(), + ); + graph_benchmark( + c, + "graphgen_large_balance_layered", + 20, + 10, + large_weighted_random_attachment_layered, + |graph, _| balance(graph, "weight".to_string(), Direction::BOTH).unwrap(), ) } @@ -421,6 +811,22 @@ pub fn graphgen_large_max_degree(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| max_degree(graph), + ); + graph_benchmark( + c, + "graphgen_large_max_degree_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| max_degree(graph), + ); + graph_benchmark( + c, + "graphgen_large_max_degree_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| max_degree(graph), ) } @@ -432,17 +838,49 @@ pub fn graphgen_large_min_degree(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| min_degree(graph), - ) -} - -pub fn graphgen_large_max_out_degree(c: &mut Criterion) { + ); graph_benchmark( c, - "graphgen_large_max_out_degree", + "graphgen_large_min_degree_subgraph", 20, 10, - large_random_attachment_graph, - |graph, _| max_out_degree(graph), + large_random_attachment_subgraph, + |graph, _| min_degree(graph), + ); + graph_benchmark( + c, + "graphgen_large_min_degree_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| min_degree(graph), + ) +} + +pub fn graphgen_large_max_out_degree(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_max_out_degree", + 20, + 10, + large_random_attachment_graph, + |graph, _| max_out_degree(graph), + ); + graph_benchmark( + c, + "graphgen_large_max_out_degree_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| max_out_degree(graph), + ); + graph_benchmark( + c, + "graphgen_large_max_out_degree_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| max_out_degree(graph), ) } @@ -454,6 +892,22 @@ pub fn graphgen_large_max_in_degree(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| max_in_degree(graph), + ); + graph_benchmark( + c, + "graphgen_large_max_in_degree_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| max_in_degree(graph), + ); + graph_benchmark( + c, + "graphgen_large_max_in_degree_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| max_in_degree(graph), ) } @@ -465,6 +919,22 @@ pub fn graphgen_large_min_out_degree(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| min_out_degree(graph), + ); + graph_benchmark( + c, + "graphgen_large_min_out_degree_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| min_out_degree(graph), + ); + graph_benchmark( + c, + "graphgen_large_min_out_degree_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| min_out_degree(graph), ) } @@ -476,6 +946,22 @@ pub fn graphgen_large_min_in_degree(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| min_in_degree(graph), + ); + graph_benchmark( + c, + "graphgen_large_min_in_degree_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| min_in_degree(graph), + ); + graph_benchmark( + c, + "graphgen_large_min_in_degree_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| min_in_degree(graph), ) } @@ -487,6 +973,22 @@ pub fn graphgen_large_average_degree(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| average_degree(graph), + ); + graph_benchmark( + c, + "graphgen_large_average_degree_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| average_degree(graph), + ); + graph_benchmark( + c, + "graphgen_large_average_degree_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| average_degree(graph), ) } @@ -499,6 +1001,24 @@ pub fn graphgen_large_local_clustering_coefficient_batch(c: &mut Criterion) { large_random_attachment_graph, first_node_id, |graph, node_id| local_clustering_coefficient_batch(graph, vec![node_id.clone()]), + ); + graph_benchmark_with_setup( + c, + "graphgen_large_local_clustering_coefficient_batch_subgraph", + 20, + 10, + large_random_attachment_subgraph, + first_node_id, + |graph, node_id| local_clustering_coefficient_batch(graph, vec![node_id.clone()]), + ); + graph_benchmark_with_setup( + c, + "graphgen_large_local_clustering_coefficient_batch_layered", + 20, + 10, + large_random_attachment_layered, + first_node_id, + |graph, node_id| local_clustering_coefficient_batch(graph, vec![node_id.clone()]), ) } @@ -513,6 +1033,28 @@ pub fn graphgen_large_temporal_rich_club(c: &mut Criterion) { let rolling = graph.rolling(1, Some(1)).unwrap(); temporal_rich_club_coefficient(graph, rolling, 3, 3) }, + ); + graph_benchmark( + c, + "graphgen_large_temporal_rich_club_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| { + let rolling = graph.rolling(1, Some(1)).unwrap(); + temporal_rich_club_coefficient(graph, rolling, 3, 3) + }, + ); + graph_benchmark( + c, + "graphgen_large_temporal_rich_club_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| { + let rolling = graph.rolling(1, Some(1)).unwrap(); + temporal_rich_club_coefficient(graph, rolling, 3, 3) + }, ) } @@ -524,6 +1066,22 @@ pub fn graphgen_large_temporal_motif_multi(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| temporal_three_node_motif_multi(graph, vec![100], None), + ); + graph_benchmark( + c, + "graphgen_large_temporal_motif_multi_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| temporal_three_node_motif_multi(graph, vec![100], None), + ); + graph_benchmark( + c, + "graphgen_large_temporal_motif_multi_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| temporal_three_node_motif_multi(graph, vec![100], None), ) } @@ -535,6 +1093,22 @@ pub fn graphgen_large_local_temporal_motif(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| local_temporal_three_node_motif(graph, 100, None), + ); + graph_benchmark( + c, + "graphgen_large_local_temporal_motif_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| local_temporal_three_node_motif(graph, 100, None), + ); + graph_benchmark( + c, + "graphgen_large_local_temporal_motif_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| local_temporal_three_node_motif(graph, 100, None), ) } @@ -556,6 +1130,42 @@ pub fn graphgen_large_dijkstra(c: &mut Criterion) { ) .unwrap() }, + ); + graph_benchmark_with_setup( + c, + "graphgen_large_dijkstra_subgraph", + 20, + 10, + large_random_attachment_subgraph, + first_node_id, + |graph, source| { + dijkstra_single_source_shortest_paths( + graph, + source.clone(), + vec![source.clone()], + None, + Direction::BOTH, + ) + .unwrap() + }, + ); + graph_benchmark_with_setup( + c, + "graphgen_large_dijkstra_layered", + 20, + 10, + large_random_attachment_layered, + first_node_id, + |graph, source| { + dijkstra_single_source_shortest_paths( + graph, + source.clone(), + vec![source.clone()], + None, + Direction::BOTH, + ) + .unwrap() + }, ) } @@ -568,6 +1178,24 @@ pub fn graphgen_large_single_source_shortest_path(c: &mut Criterion) { large_random_attachment_graph, first_node_id, |graph, source| single_source_shortest_path(graph, source.clone(), None), + ); + graph_benchmark_with_setup( + c, + "graphgen_large_single_source_shortest_path_subgraph", + 20, + 10, + large_random_attachment_subgraph, + first_node_id, + |graph, source| single_source_shortest_path(graph, source.clone(), None), + ); + graph_benchmark_with_setup( + c, + "graphgen_large_single_source_shortest_path_layered", + 20, + 10, + large_random_attachment_layered, + first_node_id, + |graph, source| single_source_shortest_path(graph, source.clone(), None), ) } @@ -580,6 +1208,24 @@ pub fn graphgen_large_temporally_reachable_nodes(c: &mut Criterion) { large_random_attachment_graph, first_node_id, |graph, source| temporally_reachable_nodes(graph, None, 20, 0, vec![source.clone()], None), + ); + graph_benchmark_with_setup( + c, + "graphgen_large_temporally_reachable_nodes_subgraph", + 20, + 10, + large_random_attachment_subgraph, + first_node_id, + |graph, source| temporally_reachable_nodes(graph, None, 20, 0, vec![source.clone()], None), + ); + graph_benchmark_with_setup( + c, + "graphgen_large_temporally_reachable_nodes_layered", + 20, + 10, + large_random_attachment_layered, + first_node_id, + |graph, source| temporally_reachable_nodes(graph, None, 20, 0, vec![source.clone()], None), ) } @@ -595,6 +1241,30 @@ pub fn graphgen_large_in_component(c: &mut Criterion) { let node = graph.node(source.clone()).expect("source node exists"); in_component(node) }, + ); + graph_benchmark_with_setup( + c, + "graphgen_large_in_component_subgraph", + 20, + 10, + large_random_attachment_subgraph, + first_node_id, + |graph, source| { + let node = graph.node(source.clone()).expect("source node exists"); + in_component(node) + }, + ); + graph_benchmark_with_setup( + c, + "graphgen_large_in_component_layered", + 20, + 10, + large_random_attachment_layered, + first_node_id, + |graph, source| { + let node = graph.node(source.clone()).expect("source node exists"); + in_component(node) + }, ) } @@ -610,6 +1280,30 @@ pub fn graphgen_large_out_component(c: &mut Criterion) { let node = graph.node(source.clone()).expect("source node exists"); out_component(node) }, + ); + graph_benchmark_with_setup( + c, + "graphgen_large_out_component_subgraph", + 20, + 10, + large_random_attachment_subgraph, + first_node_id, + |graph, source| { + let node = graph.node(source.clone()).expect("source node exists"); + out_component(node) + }, + ); + graph_benchmark_with_setup( + c, + "graphgen_large_out_component_layered", + 20, + 10, + large_random_attachment_layered, + first_node_id, + |graph, source| { + let node = graph.node(source.clone()).expect("source node exists"); + out_component(node) + }, ) } @@ -625,6 +1319,30 @@ pub fn graphgen_large_in_component_filtered(c: &mut Criterion) { let node = graph.node(source.clone()).expect("source node exists"); in_component_filtered(node, Unfiltered).unwrap() }, + ); + graph_benchmark_with_setup( + c, + "graphgen_large_in_component_filtered_subgraph", + 20, + 10, + large_random_attachment_subgraph, + first_node_id, + |graph, source| { + let node = graph.node(source.clone()).expect("source node exists"); + in_component_filtered(node, Unfiltered).unwrap() + }, + ); + graph_benchmark_with_setup( + c, + "graphgen_large_in_component_filtered_layered", + 20, + 10, + large_random_attachment_layered, + first_node_id, + |graph, source| { + let node = graph.node(source.clone()).expect("source node exists"); + in_component_filtered(node, Unfiltered).unwrap() + }, ) } @@ -640,6 +1358,30 @@ pub fn graphgen_large_out_component_filtered(c: &mut Criterion) { let node = graph.node(source.clone()).expect("source node exists"); out_component_filtered(node, Unfiltered).unwrap() }, + ); + graph_benchmark_with_setup( + c, + "graphgen_large_out_component_filtered_subgraph", + 20, + 10, + large_random_attachment_subgraph, + first_node_id, + |graph, source| { + let node = graph.node(source.clone()).expect("source node exists"); + out_component_filtered(node, Unfiltered).unwrap() + }, + ); + graph_benchmark_with_setup( + c, + "graphgen_large_out_component_filtered_layered", + 20, + 10, + large_random_attachment_layered, + first_node_id, + |graph, source| { + let node = graph.node(source.clone()).expect("source node exists"); + out_component_filtered(node, Unfiltered).unwrap() + }, ) } @@ -687,6 +1429,22 @@ pub fn graphgen_internal_global_triangle_motifs(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| global_triangle_motifs_internal(graph, vec![100], None), + ); + graph_benchmark( + c, + "graphgen_internal_global_triangle_motifs_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| global_triangle_motifs_internal(graph, vec![100], None), + ); + graph_benchmark( + c, + "graphgen_internal_global_triangle_motifs_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| global_triangle_motifs_internal(graph, vec![100], None), ) } @@ -698,6 +1456,22 @@ pub fn graphgen_internal_local_triangle_motifs(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| local_triangle_motifs_internal(graph, vec![100], None), + ); + graph_benchmark( + c, + "graphgen_internal_local_triangle_motifs_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| local_triangle_motifs_internal(graph, vec![100], None), + ); + graph_benchmark( + c, + "graphgen_internal_local_triangle_motifs_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| local_triangle_motifs_internal(graph, vec![100], None), ) } @@ -709,6 +1483,22 @@ pub fn graphgen_large_k_core_set(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| k_core_set(graph, 2, usize::MAX, None), + ); + graph_benchmark( + c, + "graphgen_large_k_core_set_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| k_core_set(graph, 2, usize::MAX, None), + ); + graph_benchmark( + c, + "graphgen_large_k_core_set_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| k_core_set(graph, 2, usize::MAX, None), ) } @@ -720,6 +1510,22 @@ pub fn graphgen_large_k_core(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| k_core(graph, 2, usize::MAX, None), + ); + graph_benchmark( + c, + "graphgen_large_k_core_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| k_core(graph, 2, usize::MAX, None), + ); + graph_benchmark( + c, + "graphgen_large_k_core_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| k_core(graph, 2, usize::MAX, None), ) } @@ -731,6 +1537,22 @@ pub fn graphgen_large_fruchterman_reingold(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| fruchterman_reingold_unbounded(graph, 5, 1.0, 1.0, 0.9, 0.1), + ); + graph_benchmark( + c, + "graphgen_large_fruchterman_reingold_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| fruchterman_reingold_unbounded(graph, 5, 1.0, 1.0, 0.9, 0.1), + ); + graph_benchmark( + c, + "graphgen_large_fruchterman_reingold_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| fruchterman_reingold_unbounded(graph, 5, 1.0, 1.0, 0.9, 0.1), ) } @@ -742,6 +1564,22 @@ pub fn graphgen_large_cohesive_fruchterman_reingold(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| cohesive_fruchterman_reingold(graph, 5, 1.0, 1.0, 0.9, 0.1), + ); + graph_benchmark( + c, + "graphgen_large_cohesive_fruchterman_reingold_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| cohesive_fruchterman_reingold(graph, 5, 1.0, 1.0, 0.9, 0.1), + ); + graph_benchmark( + c, + "graphgen_large_cohesive_fruchterman_reingold_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| cohesive_fruchterman_reingold(graph, 5, 1.0, 1.0, 0.9, 0.1), ) } @@ -753,6 +1591,22 @@ pub fn graphgen_large_fast_rp(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| fast_rp(graph, 32, 0.5, vec![1.0, 1.0, 1.0], Some(1), None), + ); + graph_benchmark( + c, + "graphgen_large_fast_rp_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| fast_rp(graph, 32, 0.5, vec![1.0, 1.0, 1.0], Some(1), None), + ); + graph_benchmark( + c, + "graphgen_large_fast_rp_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| fast_rp(graph, 32, 0.5, vec![1.0, 1.0, 1.0], Some(1), None), ) } @@ -764,6 +1618,22 @@ pub fn graphgen_large_max_weight_matching(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| max_weight_matching(graph, None, false, false), + ); + graph_benchmark( + c, + "graphgen_large_max_weight_matching_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| max_weight_matching(graph, None, false, false), + ); + graph_benchmark( + c, + "graphgen_large_max_weight_matching_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| max_weight_matching(graph, None, false, false), ) } @@ -778,6 +1648,28 @@ pub fn graphgen_large_temporal_seir(c: &mut Criterion) { let mut rng = SmallRng::seed_from_u64(1); temporal_SEIR(graph, Some(0.1), None, 0.5f64, 0, Number(1), &mut rng).unwrap() }, + ); + graph_benchmark( + c, + "graphgen_large_temporal_seir_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| { + let mut rng = SmallRng::seed_from_u64(1); + temporal_SEIR(graph, Some(0.1), None, 0.5f64, 0, Number(1), &mut rng).unwrap() + }, + ); + graph_benchmark( + c, + "graphgen_large_temporal_seir_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| { + let mut rng = SmallRng::seed_from_u64(1); + temporal_SEIR(graph, Some(0.1), None, 0.5f64, 0, Number(1), &mut rng).unwrap() + }, ) } @@ -789,6 +1681,22 @@ pub fn graphgen_large_temporal_bipartite_projection(c: &mut Criterion) { 10, large_typed_random_attachment_graph, |graph, _| temporal_bipartite_projection(graph, 1, "Right".to_string()), + ); + graph_benchmark( + c, + "graphgen_large_temporal_bipartite_projection_subgraph", + 20, + 10, + large_typed_random_attachment_subgraph, + |graph, _| temporal_bipartite_projection(graph, 1, "Right".to_string()), + ); + graph_benchmark( + c, + "graphgen_large_temporal_bipartite_projection_layered", + 20, + 10, + large_typed_random_attachment_layered, + |graph, _| temporal_bipartite_projection(graph, 1, "Right".to_string()), ) } @@ -800,6 +1708,22 @@ pub fn temporal_motifs(c: &mut Criterion) { 10, large_random_attachment_graph, |graph, _| global_temporal_three_node_motif(graph, 100, None), + ); + graph_benchmark( + c, + "temporal_motifs_subgraph", + 20, + 10, + large_random_attachment_subgraph, + |graph, _| global_temporal_three_node_motif(graph, 100, None), + ); + graph_benchmark( + c, + "temporal_motifs_layered", + 20, + 10, + large_random_attachment_layered, + |graph, _| global_temporal_three_node_motif(graph, 100, None), ) } @@ -863,4 +1787,4 @@ criterion_group!( graphgen_internal_local_triangle_motifs, temporal_motifs, ); -criterion_main!(benches); +criterion_main!(benches); \ No newline at end of file From d438a3d5d8c3d3713491e4c958dfd328bff93c75 Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Sun, 21 Jun 2026 20:02:56 -0500 Subject: [PATCH 10/24] working --- raphtory-benchmark/benches/algobench.rs | 471 +++++++++++++++++++++++- 1 file changed, 470 insertions(+), 1 deletion(-) diff --git a/raphtory-benchmark/benches/algobench.rs b/raphtory-benchmark/benches/algobench.rs index 116525b403..20313ab813 100644 --- a/raphtory-benchmark/benches/algobench.rs +++ b/raphtory-benchmark/benches/algobench.rs @@ -58,7 +58,13 @@ use raphtory::{ }, projections::temporal_bipartite_projection::temporal_bipartite_projection, }, - db::{api::view::StaticGraphViewOps, graph::views::{filter::Unfiltered, node_subgraph::NodeSubgraph}}, + db::{ + api::view::{Filter, StaticGraphViewOps}, + graph::views::{ + filter::{Unfiltered, model::{degree_filter::DegreeFilterFactory, property_filter::ops::PropertyFilterOps}}, + node_subgraph::NodeSubgraph, + }, + }, graphgen::random_attachment::random_attachment, prelude::*, }; @@ -171,6 +177,18 @@ fn large_weighted_random_attachment_subgraph() -> NodeSubgraph { subgraph } +fn large_random_attachment_filtered() -> impl StaticGraphViewOps { + large_random_attachment_graph() + .filter(NodeFilter.degree().ge(0u64)) + .unwrap() +} + +fn large_weighted_random_attachment_filtered() -> impl StaticGraphViewOps { + large_weighted_random_attachment_graph() + .filter(NodeFilter.degree().ge(0u64)) + .unwrap() +} + fn large_typed_random_attachment_graph() -> Graph { let graph = large_random_attachment_graph(); for id in graph.nodes().id().iter_values() { @@ -187,6 +205,12 @@ fn large_typed_random_attachment_subgraph() -> NodeSubgraph { subgraph } +fn large_typed_random_attachment_filtered() -> impl StaticGraphViewOps { + large_typed_random_attachment_graph() + .filter(NodeFilter.degree().ge(0u64)) + .unwrap() +} + fn large_random_attachment_layered() -> impl StaticGraphViewOps { let graph = large_random_attachment_graph(); graph.default_layer() @@ -231,6 +255,15 @@ pub fn local_triangle_count_analysis(c: &mut Criterion) { first_node_id, |graph, node_id| local_triangle_count(graph, node_id.clone()).unwrap(), ); + graph_benchmark_with_setup( + c, + "local_triangle_count_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + first_node_id, + |graph, node_id| local_triangle_count(graph, node_id.clone()).unwrap(), + ); } pub fn local_clustering_coefficient_analysis(c: &mut Criterion) { @@ -260,6 +293,15 @@ pub fn local_clustering_coefficient_analysis(c: &mut Criterion) { large_random_attachment_layered, first_node_id, |graph, node_id| local_clustering_coefficient(graph, node_id.clone()), + ); + graph_benchmark_with_setup( + c, + "local_clustering_coefficient_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + first_node_id, + |graph, node_id| local_clustering_coefficient(graph, node_id.clone()), ) } @@ -287,6 +329,14 @@ pub fn graphgen_large_clustering_coeff(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| global_clustering_coefficient(graph), + ); + graph_benchmark( + c, + "graphgen_large_clustering_coeff_graph_filtered", + 60, + 10, + large_random_attachment_filtered, + |graph, _| global_clustering_coefficient(graph), ) } @@ -314,6 +364,14 @@ pub fn graphgen_large_pagerank(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| page_rank(graph, None, Some(100), None, None, true, None), + ); + graph_benchmark( + c, + "graphgen_large_pagerank_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| page_rank(graph, None, Some(100), None, None, true, None), ) } @@ -341,6 +399,14 @@ pub fn graphgen_large_concomp(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| weakly_connected_components(graph), + ); + graph_benchmark( + c, + "graphgen_large_concomp_graph_filtered", + 60, + 10, + large_random_attachment_filtered, + |graph, _| weakly_connected_components(graph), ) } @@ -368,6 +434,14 @@ pub fn graphgen_large_hits(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| hits(graph, 100, None), + ); + graph_benchmark( + c, + "graphgen_large_hits_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| hits(graph, 100, None), ) } @@ -395,6 +469,14 @@ pub fn graphgen_large_degree_centrality(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| degree_centrality(graph), + ); + graph_benchmark( + c, + "graphgen_large_degree_centrality_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| degree_centrality(graph), ) } @@ -422,6 +504,14 @@ pub fn graphgen_large_betweenness(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| betweenness_centrality(graph, None, false), + ); + graph_benchmark( + c, + "graphgen_large_betweenness_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| betweenness_centrality(graph, None, false), ) } @@ -449,6 +539,14 @@ pub fn graphgen_large_triangle_count(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| triangle_count(graph, None), + ); + graph_benchmark( + c, + "graphgen_large_triangle_count_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| triangle_count(graph, None), ) } @@ -476,6 +574,14 @@ pub fn graphgen_large_triplet_count(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| triplet_count(graph, None), + ); + graph_benchmark( + c, + "graphgen_large_triplet_count_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| triplet_count(graph, None), ) } @@ -503,6 +609,14 @@ pub fn graphgen_large_directed_density(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| directed_graph_density(graph), + ); + graph_benchmark( + c, + "graphgen_large_directed_density_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| directed_graph_density(graph), ) } @@ -530,6 +644,14 @@ pub fn graphgen_large_reciprocity(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| global_reciprocity(graph), + ); + graph_benchmark( + c, + "graphgen_large_reciprocity_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| global_reciprocity(graph), ) } @@ -557,6 +679,14 @@ pub fn graphgen_large_scc(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| strongly_connected_components(graph), + ); + graph_benchmark( + c, + "graphgen_large_scc_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| strongly_connected_components(graph), ) } @@ -584,6 +714,14 @@ pub fn graphgen_large_in_components(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| in_components(graph, None), + ); + graph_benchmark( + c, + "graphgen_large_in_components_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| in_components(graph, None), ) } @@ -611,6 +749,14 @@ pub fn graphgen_large_out_components(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| out_components(graph, None), + ); + graph_benchmark( + c, + "graphgen_large_out_components_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| out_components(graph, None), ) } @@ -638,6 +784,14 @@ pub fn graphgen_large_in_components_filtered(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| in_components_filtered(graph, None, Unfiltered).unwrap(), + ); + graph_benchmark( + c, + "graphgen_large_in_components_filtered_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| in_components_filtered(graph, None, Unfiltered).unwrap(), ) } @@ -665,6 +819,14 @@ pub fn graphgen_large_out_components_filtered(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| out_components_filtered(graph, None, Unfiltered).unwrap(), + ); + graph_benchmark( + c, + "graphgen_large_out_components_filtered_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| out_components_filtered(graph, None, Unfiltered).unwrap(), ) } @@ -692,6 +854,14 @@ pub fn graphgen_large_label_propagation(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| label_propagation(graph, 20, Some([1; 32]), None), + ); + graph_benchmark( + c, + "graphgen_large_label_propagation_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| label_propagation(graph, 20, Some([1; 32]), None), ) } @@ -719,6 +889,14 @@ pub fn graphgen_large_louvain(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| louvain::(graph, 1.0, None, None), + ); + graph_benchmark( + c, + "graphgen_large_louvain_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| louvain::(graph, 1.0, None, None), ) } @@ -746,6 +924,14 @@ pub fn graphgen_large_alternating_mask(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| alternating_mask(graph), + ); + graph_benchmark( + c, + "graphgen_large_alternating_mask_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| alternating_mask(graph), ) } @@ -773,6 +959,14 @@ pub fn graphgen_large_all_local_reciprocity(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| all_local_reciprocity(graph), + ); + graph_benchmark( + c, + "graphgen_large_all_local_reciprocity_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| all_local_reciprocity(graph), ) } @@ -800,6 +994,14 @@ pub fn graphgen_large_balance(c: &mut Criterion) { 10, large_weighted_random_attachment_layered, |graph, _| balance(graph, "weight".to_string(), Direction::BOTH).unwrap(), + ); + graph_benchmark( + c, + "graphgen_large_balance_graph_filtered", + 20, + 10, + large_weighted_random_attachment_filtered, + |graph, _| balance(graph, "weight".to_string(), Direction::BOTH).unwrap(), ) } @@ -827,6 +1029,14 @@ pub fn graphgen_large_max_degree(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| max_degree(graph), + ); + graph_benchmark( + c, + "graphgen_large_max_degree_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| max_degree(graph), ) } @@ -854,6 +1064,14 @@ pub fn graphgen_large_min_degree(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| min_degree(graph), + ); + graph_benchmark( + c, + "graphgen_large_min_degree_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| min_degree(graph), ) } @@ -881,6 +1099,14 @@ pub fn graphgen_large_max_out_degree(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| max_out_degree(graph), + ); + graph_benchmark( + c, + "graphgen_large_max_out_degree_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| max_out_degree(graph), ) } @@ -908,6 +1134,14 @@ pub fn graphgen_large_max_in_degree(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| max_in_degree(graph), + ); + graph_benchmark( + c, + "graphgen_large_max_in_degree_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| max_in_degree(graph), ) } @@ -935,6 +1169,14 @@ pub fn graphgen_large_min_out_degree(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| min_out_degree(graph), + ); + graph_benchmark( + c, + "graphgen_large_min_out_degree_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| min_out_degree(graph), ) } @@ -962,6 +1204,14 @@ pub fn graphgen_large_min_in_degree(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| min_in_degree(graph), + ); + graph_benchmark( + c, + "graphgen_large_min_in_degree_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| min_in_degree(graph), ) } @@ -989,6 +1239,14 @@ pub fn graphgen_large_average_degree(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| average_degree(graph), + ); + graph_benchmark( + c, + "graphgen_large_average_degree_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| average_degree(graph), ) } @@ -1019,6 +1277,15 @@ pub fn graphgen_large_local_clustering_coefficient_batch(c: &mut Criterion) { large_random_attachment_layered, first_node_id, |graph, node_id| local_clustering_coefficient_batch(graph, vec![node_id.clone()]), + ); + graph_benchmark_with_setup( + c, + "graphgen_large_local_clustering_coefficient_batch_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + first_node_id, + |graph, node_id| local_clustering_coefficient_batch(graph, vec![node_id.clone()]), ) } @@ -1055,6 +1322,17 @@ pub fn graphgen_large_temporal_rich_club(c: &mut Criterion) { let rolling = graph.rolling(1, Some(1)).unwrap(); temporal_rich_club_coefficient(graph, rolling, 3, 3) }, + ); + graph_benchmark( + c, + "graphgen_large_temporal_rich_club_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| { + let rolling = graph.rolling(1, Some(1)).unwrap(); + temporal_rich_club_coefficient(graph, rolling, 3, 3) + }, ) } @@ -1082,6 +1360,14 @@ pub fn graphgen_large_temporal_motif_multi(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| temporal_three_node_motif_multi(graph, vec![100], None), + ); + graph_benchmark( + c, + "graphgen_large_temporal_motif_multi_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| temporal_three_node_motif_multi(graph, vec![100], None), ) } @@ -1109,6 +1395,14 @@ pub fn graphgen_large_local_temporal_motif(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| local_temporal_three_node_motif(graph, 100, None), + ); + graph_benchmark( + c, + "graphgen_large_local_temporal_motif_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| local_temporal_three_node_motif(graph, 100, None), ) } @@ -1166,6 +1460,24 @@ pub fn graphgen_large_dijkstra(c: &mut Criterion) { ) .unwrap() }, + ); + graph_benchmark_with_setup( + c, + "graphgen_large_dijkstra_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + first_node_id, + |graph, source| { + dijkstra_single_source_shortest_paths( + graph, + source.clone(), + vec![source.clone()], + None, + Direction::BOTH, + ) + .unwrap() + }, ) } @@ -1196,6 +1508,15 @@ pub fn graphgen_large_single_source_shortest_path(c: &mut Criterion) { large_random_attachment_layered, first_node_id, |graph, source| single_source_shortest_path(graph, source.clone(), None), + ); + graph_benchmark_with_setup( + c, + "graphgen_large_single_source_shortest_path_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + first_node_id, + |graph, source| single_source_shortest_path(graph, source.clone(), None), ) } @@ -1226,6 +1547,15 @@ pub fn graphgen_large_temporally_reachable_nodes(c: &mut Criterion) { large_random_attachment_layered, first_node_id, |graph, source| temporally_reachable_nodes(graph, None, 20, 0, vec![source.clone()], None), + ); + graph_benchmark_with_setup( + c, + "graphgen_large_temporally_reachable_nodes_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + first_node_id, + |graph, source| temporally_reachable_nodes(graph, None, 20, 0, vec![source.clone()], None), ) } @@ -1265,6 +1595,18 @@ pub fn graphgen_large_in_component(c: &mut Criterion) { let node = graph.node(source.clone()).expect("source node exists"); in_component(node) }, + ); + graph_benchmark_with_setup( + c, + "graphgen_large_in_component_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + first_node_id, + |graph, source| { + let node = graph.node(source.clone()).expect("source node exists"); + in_component(node) + }, ) } @@ -1304,6 +1646,18 @@ pub fn graphgen_large_out_component(c: &mut Criterion) { let node = graph.node(source.clone()).expect("source node exists"); out_component(node) }, + ); + graph_benchmark_with_setup( + c, + "graphgen_large_out_component_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + first_node_id, + |graph, source| { + let node = graph.node(source.clone()).expect("source node exists"); + out_component(node) + }, ) } @@ -1343,6 +1697,18 @@ pub fn graphgen_large_in_component_filtered(c: &mut Criterion) { let node = graph.node(source.clone()).expect("source node exists"); in_component_filtered(node, Unfiltered).unwrap() }, + ); + graph_benchmark_with_setup( + c, + "graphgen_large_in_component_filtered_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + first_node_id, + |graph, source| { + let node = graph.node(source.clone()).expect("source node exists"); + in_component_filtered(node, Unfiltered).unwrap() + }, ) } @@ -1382,6 +1748,18 @@ pub fn graphgen_large_out_component_filtered(c: &mut Criterion) { let node = graph.node(source.clone()).expect("source node exists"); out_component_filtered(node, Unfiltered).unwrap() }, + ); + graph_benchmark_with_setup( + c, + "graphgen_large_out_component_filtered_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + first_node_id, + |graph, source| { + let node = graph.node(source.clone()).expect("source node exists"); + out_component_filtered(node, Unfiltered).unwrap() + }, ) } @@ -1445,6 +1823,14 @@ pub fn graphgen_internal_global_triangle_motifs(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| global_triangle_motifs_internal(graph, vec![100], None), + ); + graph_benchmark( + c, + "graphgen_internal_global_triangle_motifs_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| global_triangle_motifs_internal(graph, vec![100], None), ) } @@ -1472,6 +1858,14 @@ pub fn graphgen_internal_local_triangle_motifs(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| local_triangle_motifs_internal(graph, vec![100], None), + ); + graph_benchmark( + c, + "graphgen_internal_local_triangle_motifs_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| local_triangle_motifs_internal(graph, vec![100], None), ) } @@ -1499,6 +1893,14 @@ pub fn graphgen_large_k_core_set(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| k_core_set(graph, 2, usize::MAX, None), + ); + graph_benchmark( + c, + "graphgen_large_k_core_set_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| k_core_set(graph, 2, usize::MAX, None), ) } @@ -1526,6 +1928,14 @@ pub fn graphgen_large_k_core(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| k_core(graph, 2, usize::MAX, None), + ); + graph_benchmark( + c, + "graphgen_large_k_core_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| k_core(graph, 2, usize::MAX, None), ) } @@ -1553,6 +1963,14 @@ pub fn graphgen_large_fruchterman_reingold(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| fruchterman_reingold_unbounded(graph, 5, 1.0, 1.0, 0.9, 0.1), + ); + graph_benchmark( + c, + "graphgen_large_fruchterman_reingold_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| fruchterman_reingold_unbounded(graph, 5, 1.0, 1.0, 0.9, 0.1), ) } @@ -1580,6 +1998,14 @@ pub fn graphgen_large_cohesive_fruchterman_reingold(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| cohesive_fruchterman_reingold(graph, 5, 1.0, 1.0, 0.9, 0.1), + ); + graph_benchmark( + c, + "graphgen_large_cohesive_fruchterman_reingold_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| cohesive_fruchterman_reingold(graph, 5, 1.0, 1.0, 0.9, 0.1), ) } @@ -1607,6 +2033,14 @@ pub fn graphgen_large_fast_rp(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| fast_rp(graph, 32, 0.5, vec![1.0, 1.0, 1.0], Some(1), None), + ); + graph_benchmark( + c, + "graphgen_large_fast_rp_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| fast_rp(graph, 32, 0.5, vec![1.0, 1.0, 1.0], Some(1), None), ) } @@ -1634,6 +2068,14 @@ pub fn graphgen_large_max_weight_matching(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| max_weight_matching(graph, None, false, false), + ); + graph_benchmark( + c, + "graphgen_large_max_weight_matching_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| max_weight_matching(graph, None, false, false), ) } @@ -1670,6 +2112,17 @@ pub fn graphgen_large_temporal_seir(c: &mut Criterion) { let mut rng = SmallRng::seed_from_u64(1); temporal_SEIR(graph, Some(0.1), None, 0.5f64, 0, Number(1), &mut rng).unwrap() }, + ); + graph_benchmark( + c, + "graphgen_large_temporal_seir_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| { + let mut rng = SmallRng::seed_from_u64(1); + temporal_SEIR(graph, Some(0.1), None, 0.5f64, 0, Number(1), &mut rng).unwrap() + }, ) } @@ -1697,6 +2150,14 @@ pub fn graphgen_large_temporal_bipartite_projection(c: &mut Criterion) { 10, large_typed_random_attachment_layered, |graph, _| temporal_bipartite_projection(graph, 1, "Right".to_string()), + ); + graph_benchmark( + c, + "graphgen_large_temporal_bipartite_projection_graph_filtered", + 20, + 10, + large_typed_random_attachment_filtered, + |graph, _| temporal_bipartite_projection(graph, 1, "Right".to_string()), ) } @@ -1724,6 +2185,14 @@ pub fn temporal_motifs(c: &mut Criterion) { 10, large_random_attachment_layered, |graph, _| global_temporal_three_node_motif(graph, 100, None), + ); + graph_benchmark( + c, + "temporal_motifs_graph_filtered", + 20, + 10, + large_random_attachment_filtered, + |graph, _| global_temporal_three_node_motif(graph, 100, None), ) } From 8075fbedc1e4f010c005341f332e43e75b920771 Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Mon, 22 Jun 2026 12:47:12 -0500 Subject: [PATCH 11/24] made graphs smaller --- raphtory-benchmark/benches/algobench.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/raphtory-benchmark/benches/algobench.rs b/raphtory-benchmark/benches/algobench.rs index 20313ab813..17f2641f81 100644 --- a/raphtory-benchmark/benches/algobench.rs +++ b/raphtory-benchmark/benches/algobench.rs @@ -141,7 +141,7 @@ fn simple_benchmark( fn large_random_attachment_graph() -> Graph { let graph = Graph::new(); let seed: [u8; 32] = [1; 32]; - random_attachment(&graph, 500000, 4, Some(seed)); + random_attachment(&graph, 5000, 4, Some(seed)); graph } From 6e960ded1b7d41ab0d7c804cdb95c1af851ce666 Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Tue, 21 Jul 2026 10:49:25 -0500 Subject: [PATCH 12/24] format and sync repository --- raphtory-benchmark/benches/algobench.rs | 45 +++++++++++++++++-------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/raphtory-benchmark/benches/algobench.rs b/raphtory-benchmark/benches/algobench.rs index 17f2641f81..a8fac5187c 100644 --- a/raphtory-benchmark/benches/algobench.rs +++ b/raphtory-benchmark/benches/algobench.rs @@ -1,17 +1,15 @@ -use criterion::{criterion_group, criterion_main, Criterion, SamplingMode}; +use criterion::{criterion_group, criterion_main, Criterion, SamplingMode}; use rand::{rngs::SmallRng, SeedableRng}; use raphtory::{ algorithms::{ alternating_mask::alternating_mask, bipartite::max_weight_matching::max_weight_matching, centrality::{ - betweenness::betweenness_centrality, degree_centrality::degree_centrality, - hits::hits, pagerank::page_rank, + betweenness::betweenness_centrality, degree_centrality::degree_centrality, hits::hits, + pagerank::page_rank, }, community_detection::{ - label_propagation::label_propagation, - louvain::louvain, - modularity::ModularityUnDir, + label_propagation::label_propagation, louvain::louvain, modularity::ModularityUnDir, }, components::{ in_component, in_component_filtered, in_components, in_components_filtered, @@ -19,7 +17,7 @@ use raphtory::{ strongly_connected_components, weakly_connected_components, }, cores::k_core::{k_core, k_core_set}, - dynamics::temporal::epidemics::{Number, temporal_SEIR}, + dynamics::temporal::epidemics::{temporal_SEIR, Number}, embeddings::fast_rp::fast_rp, layout::{ cohesive_fruchterman_reingold::cohesive_fruchterman_reingold, @@ -43,13 +41,19 @@ use raphtory::{ global_temporal_three_node_motifs::{ global_temporal_three_node_motif, temporal_three_node_motif_multi, triangle_motifs as global_triangle_motifs_internal, - }, local_temporal_three_node_motifs::{ + }, + local_temporal_three_node_motifs::{ temporal_three_node_motif as local_temporal_three_node_motif, triangle_motifs as local_triangle_motifs_internal, - }, local_triangle_count::local_triangle_count, temporal_rich_club_coefficient::temporal_rich_club_coefficient, three_node_motifs::{ + }, + local_triangle_count::local_triangle_count, + temporal_rich_club_coefficient::temporal_rich_club_coefficient, + three_node_motifs::{ init_star_count, init_tri_count, init_two_node_count, new_triangle_edge, star_event, two_node_event, - }, triangle_count::triangle_count, triplet_count::triplet_count + }, + triangle_count::triangle_count, + triplet_count::triplet_count, }, pathing::{ dijkstra::dijkstra_single_source_shortest_paths, @@ -61,7 +65,12 @@ use raphtory::{ db::{ api::view::{Filter, StaticGraphViewOps}, graph::views::{ - filter::{Unfiltered, model::{degree_filter::DegreeFilterFactory, property_filter::ops::PropertyFilterOps}}, + filter::{ + model::{ + degree_filter::DegreeFilterFactory, property_filter::ops::PropertyFilterOps, + }, + Unfiltered, + }, node_subgraph::NodeSubgraph, }, }, @@ -113,7 +122,15 @@ fn graph_benchmark( BuildGraph: FnOnce() -> G, Run: FnMut(&G, &()) -> Output, { - graph_benchmark_with_setup(c, name, measurement_secs, sample_size, build_graph, |_| (), run) + graph_benchmark_with_setup( + c, + name, + measurement_secs, + sample_size, + build_graph, + |_| (), + run, + ) } fn simple_benchmark( @@ -149,7 +166,7 @@ fn large_random_attachment_subgraph() -> NodeSubgraph { let graph = large_random_attachment_graph(); let subgraph = graph.subgraph(graph.nodes()); subgraph -} +} fn first_node_id(graph: &G) -> GID { graph @@ -2256,4 +2273,4 @@ criterion_group!( graphgen_internal_local_triangle_motifs, temporal_motifs, ); -criterion_main!(benches); \ No newline at end of file +criterion_main!(benches); From a88a1887f9264fa8d5b5661ade036dbb9f156fcb Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Tue, 21 Jul 2026 10:54:05 -0500 Subject: [PATCH 13/24] add comments --- raphtory-benchmark/benches/algobench.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/raphtory-benchmark/benches/algobench.rs b/raphtory-benchmark/benches/algobench.rs index a8fac5187c..e323a0b9d3 100644 --- a/raphtory-benchmark/benches/algobench.rs +++ b/raphtory-benchmark/benches/algobench.rs @@ -155,6 +155,8 @@ fn simple_benchmark( group.finish() } +// Graph Constructors + fn large_random_attachment_graph() -> Graph { let graph = Graph::new(); let seed: [u8; 32] = [1; 32]; @@ -243,6 +245,8 @@ fn large_typed_random_attachment_layered() -> impl StaticGraphViewOps { graph.default_layer() } +// Benchmarks + pub fn local_triangle_count_analysis(c: &mut Criterion) { graph_benchmark_with_setup( c, From 83673353857006e7eff07d8f962fcbdada33eb2f Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Tue, 21 Jul 2026 18:45:38 -0500 Subject: [PATCH 14/24] fix louvain issue --- raphtory-benchmark/benches/algobench.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/raphtory-benchmark/benches/algobench.rs b/raphtory-benchmark/benches/algobench.rs index e323a0b9d3..511e042e14 100644 --- a/raphtory-benchmark/benches/algobench.rs +++ b/raphtory-benchmark/benches/algobench.rs @@ -893,7 +893,7 @@ pub fn graphgen_large_louvain(c: &mut Criterion) { 20, 10, large_random_attachment_graph, - |graph, _| louvain::(graph, 1.0, None, None), + |graph, _| louvain::(graph, 1.0, None, None, Some(42)), ); graph_benchmark( c, @@ -901,7 +901,7 @@ pub fn graphgen_large_louvain(c: &mut Criterion) { 20, 10, large_random_attachment_subgraph, - |graph, _| louvain::(graph, 1.0, None, None), + |graph, _| louvain::(graph, 1.0, None, None, Some(42)), ); graph_benchmark( c, @@ -909,7 +909,7 @@ pub fn graphgen_large_louvain(c: &mut Criterion) { 20, 10, large_random_attachment_layered, - |graph, _| louvain::(graph, 1.0, None, None), + |graph, _| louvain::(graph, 1.0, None, None, Some(42)), ); graph_benchmark( c, @@ -917,7 +917,7 @@ pub fn graphgen_large_louvain(c: &mut Criterion) { 20, 10, large_random_attachment_filtered, - |graph, _| louvain::(graph, 1.0, None, None), + |graph, _| louvain::(graph, 1.0, None, None, Some(42)), ) } From 56a733716e3cf83f091a7db5643664d3e6496bb6 Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Wed, 22 Jul 2026 14:17:07 -0500 Subject: [PATCH 15/24] made it so theres small graphs for heavier algorithms --- raphtory-benchmark/benches/algobench.rs | 96 +++++++++++++++---------- 1 file changed, 60 insertions(+), 36 deletions(-) diff --git a/raphtory-benchmark/benches/algobench.rs b/raphtory-benchmark/benches/algobench.rs index 511e042e14..d9264eb830 100644 --- a/raphtory-benchmark/benches/algobench.rs +++ b/raphtory-benchmark/benches/algobench.rs @@ -245,6 +245,30 @@ fn large_typed_random_attachment_layered() -> impl StaticGraphViewOps { graph.default_layer() } +fn small_random_attachment_graph() -> Graph { + let graph = Graph::new(); + let seed: [u8; 32] = [1; 32]; + random_attachment(&graph, 500, 4, Some(seed)); + graph +} + +fn small_random_attachment_subgraph() -> NodeSubgraph { + let graph = small_random_attachment_graph(); + let subgraph = graph.subgraph(graph.nodes()); + subgraph +} + +fn small_random_attachment_filtered() -> impl StaticGraphViewOps { + small_random_attachment_graph() + .filter(NodeFilter.degree().ge(0u64)) + .unwrap() +} + +fn small_random_attachment_layered() -> impl StaticGraphViewOps { + let graph = small_random_attachment_graph(); + graph.default_layer() +} + // Benchmarks pub fn local_triangle_count_analysis(c: &mut Criterion) { @@ -507,7 +531,7 @@ pub fn graphgen_large_betweenness(c: &mut Criterion) { "graphgen_large_betweenness", 20, 10, - large_random_attachment_graph, + small_random_attachment_graph, |graph, _| betweenness_centrality(graph, None, false), ); graph_benchmark( @@ -515,7 +539,7 @@ pub fn graphgen_large_betweenness(c: &mut Criterion) { "graphgen_large_betweenness_subgraph", 20, 10, - large_random_attachment_subgraph, + small_random_attachment_subgraph, |graph, _| betweenness_centrality(graph, None, false), ); graph_benchmark( @@ -523,7 +547,7 @@ pub fn graphgen_large_betweenness(c: &mut Criterion) { "graphgen_large_betweenness_layered", 20, 10, - large_random_attachment_layered, + small_random_attachment_layered, |graph, _| betweenness_centrality(graph, None, false), ); graph_benchmark( @@ -531,7 +555,7 @@ pub fn graphgen_large_betweenness(c: &mut Criterion) { "graphgen_large_betweenness_graph_filtered", 20, 10, - large_random_attachment_filtered, + small_random_attachment_filtered, |graph, _| betweenness_centrality(graph, None, false), ) } @@ -717,7 +741,7 @@ pub fn graphgen_large_in_components(c: &mut Criterion) { "graphgen_large_in_components", 20, 10, - large_random_attachment_graph, + small_random_attachment_graph, |graph, _| in_components(graph, None), ); graph_benchmark( @@ -725,7 +749,7 @@ pub fn graphgen_large_in_components(c: &mut Criterion) { "graphgen_large_in_components_subgraph", 20, 10, - large_random_attachment_subgraph, + small_random_attachment_subgraph, |graph, _| in_components(graph, None), ); graph_benchmark( @@ -733,7 +757,7 @@ pub fn graphgen_large_in_components(c: &mut Criterion) { "graphgen_large_in_components_layered", 20, 10, - large_random_attachment_layered, + small_random_attachment_layered, |graph, _| in_components(graph, None), ); graph_benchmark( @@ -741,7 +765,7 @@ pub fn graphgen_large_in_components(c: &mut Criterion) { "graphgen_large_in_components_graph_filtered", 20, 10, - large_random_attachment_filtered, + small_random_attachment_filtered, |graph, _| in_components(graph, None), ) } @@ -752,7 +776,7 @@ pub fn graphgen_large_out_components(c: &mut Criterion) { "graphgen_large_out_components", 20, 10, - large_random_attachment_graph, + small_random_attachment_graph, |graph, _| out_components(graph, None), ); graph_benchmark( @@ -760,7 +784,7 @@ pub fn graphgen_large_out_components(c: &mut Criterion) { "graphgen_large_out_components_subgraph", 20, 10, - large_random_attachment_subgraph, + small_random_attachment_subgraph, |graph, _| out_components(graph, None), ); graph_benchmark( @@ -768,7 +792,7 @@ pub fn graphgen_large_out_components(c: &mut Criterion) { "graphgen_large_out_components_layered", 20, 10, - large_random_attachment_layered, + small_random_attachment_layered, |graph, _| out_components(graph, None), ); graph_benchmark( @@ -776,7 +800,7 @@ pub fn graphgen_large_out_components(c: &mut Criterion) { "graphgen_large_out_components_graph_filtered", 20, 10, - large_random_attachment_filtered, + small_random_attachment_filtered, |graph, _| out_components(graph, None), ) } @@ -787,7 +811,7 @@ pub fn graphgen_large_in_components_filtered(c: &mut Criterion) { "graphgen_large_in_components_filtered", 20, 10, - large_random_attachment_graph, + small_random_attachment_graph, |graph, _| in_components_filtered(graph, None, Unfiltered).unwrap(), ); graph_benchmark( @@ -795,7 +819,7 @@ pub fn graphgen_large_in_components_filtered(c: &mut Criterion) { "graphgen_large_in_components_filtered_subgraph", 20, 10, - large_random_attachment_subgraph, + small_random_attachment_subgraph, |graph, _| in_components_filtered(graph, None, Unfiltered).unwrap(), ); graph_benchmark( @@ -803,7 +827,7 @@ pub fn graphgen_large_in_components_filtered(c: &mut Criterion) { "graphgen_large_in_components_filtered_layered", 20, 10, - large_random_attachment_layered, + small_random_attachment_layered, |graph, _| in_components_filtered(graph, None, Unfiltered).unwrap(), ); graph_benchmark( @@ -811,7 +835,7 @@ pub fn graphgen_large_in_components_filtered(c: &mut Criterion) { "graphgen_large_in_components_filtered_graph_filtered", 20, 10, - large_random_attachment_filtered, + small_random_attachment_filtered, |graph, _| in_components_filtered(graph, None, Unfiltered).unwrap(), ) } @@ -822,7 +846,7 @@ pub fn graphgen_large_out_components_filtered(c: &mut Criterion) { "graphgen_large_out_components_filtered", 20, 10, - large_random_attachment_graph, + small_random_attachment_graph, |graph, _| out_components_filtered(graph, None, Unfiltered).unwrap(), ); graph_benchmark( @@ -830,7 +854,7 @@ pub fn graphgen_large_out_components_filtered(c: &mut Criterion) { "graphgen_large_out_components_filtered_subgraph", 20, 10, - large_random_attachment_subgraph, + small_random_attachment_subgraph, |graph, _| out_components_filtered(graph, None, Unfiltered).unwrap(), ); graph_benchmark( @@ -838,7 +862,7 @@ pub fn graphgen_large_out_components_filtered(c: &mut Criterion) { "graphgen_large_out_components_filtered_layered", 20, 10, - large_random_attachment_layered, + small_random_attachment_layered, |graph, _| out_components_filtered(graph, None, Unfiltered).unwrap(), ); graph_benchmark( @@ -846,7 +870,7 @@ pub fn graphgen_large_out_components_filtered(c: &mut Criterion) { "graphgen_large_out_components_filtered_graph_filtered", 20, 10, - large_random_attachment_filtered, + small_random_attachment_filtered, |graph, _| out_components_filtered(graph, None, Unfiltered).unwrap(), ) } @@ -1316,7 +1340,7 @@ pub fn graphgen_large_temporal_rich_club(c: &mut Criterion) { "graphgen_large_temporal_rich_club", 20, 10, - large_random_attachment_graph, + small_random_attachment_graph, |graph, _| { let rolling = graph.rolling(1, Some(1)).unwrap(); temporal_rich_club_coefficient(graph, rolling, 3, 3) @@ -1327,7 +1351,7 @@ pub fn graphgen_large_temporal_rich_club(c: &mut Criterion) { "graphgen_large_temporal_rich_club_subgraph", 20, 10, - large_random_attachment_subgraph, + small_random_attachment_subgraph, |graph, _| { let rolling = graph.rolling(1, Some(1)).unwrap(); temporal_rich_club_coefficient(graph, rolling, 3, 3) @@ -1338,7 +1362,7 @@ pub fn graphgen_large_temporal_rich_club(c: &mut Criterion) { "graphgen_large_temporal_rich_club_layered", 20, 10, - large_random_attachment_layered, + small_random_attachment_layered, |graph, _| { let rolling = graph.rolling(1, Some(1)).unwrap(); temporal_rich_club_coefficient(graph, rolling, 3, 3) @@ -1349,7 +1373,7 @@ pub fn graphgen_large_temporal_rich_club(c: &mut Criterion) { "graphgen_large_temporal_rich_club_graph_filtered", 20, 10, - large_random_attachment_filtered, + small_random_attachment_filtered, |graph, _| { let rolling = graph.rolling(1, Some(1)).unwrap(); temporal_rich_club_coefficient(graph, rolling, 3, 3) @@ -1966,7 +1990,7 @@ pub fn graphgen_large_fruchterman_reingold(c: &mut Criterion) { "graphgen_large_fruchterman_reingold", 20, 10, - large_random_attachment_graph, + small_random_attachment_graph, |graph, _| fruchterman_reingold_unbounded(graph, 5, 1.0, 1.0, 0.9, 0.1), ); graph_benchmark( @@ -1974,7 +1998,7 @@ pub fn graphgen_large_fruchterman_reingold(c: &mut Criterion) { "graphgen_large_fruchterman_reingold_subgraph", 20, 10, - large_random_attachment_subgraph, + small_random_attachment_subgraph, |graph, _| fruchterman_reingold_unbounded(graph, 5, 1.0, 1.0, 0.9, 0.1), ); graph_benchmark( @@ -1982,7 +2006,7 @@ pub fn graphgen_large_fruchterman_reingold(c: &mut Criterion) { "graphgen_large_fruchterman_reingold_layered", 20, 10, - large_random_attachment_layered, + small_random_attachment_layered, |graph, _| fruchterman_reingold_unbounded(graph, 5, 1.0, 1.0, 0.9, 0.1), ); graph_benchmark( @@ -1990,7 +2014,7 @@ pub fn graphgen_large_fruchterman_reingold(c: &mut Criterion) { "graphgen_large_fruchterman_reingold_graph_filtered", 20, 10, - large_random_attachment_filtered, + small_random_attachment_filtered, |graph, _| fruchterman_reingold_unbounded(graph, 5, 1.0, 1.0, 0.9, 0.1), ) } @@ -2001,7 +2025,7 @@ pub fn graphgen_large_cohesive_fruchterman_reingold(c: &mut Criterion) { "graphgen_large_cohesive_fruchterman_reingold", 20, 10, - large_random_attachment_graph, + small_random_attachment_graph, |graph, _| cohesive_fruchterman_reingold(graph, 5, 1.0, 1.0, 0.9, 0.1), ); graph_benchmark( @@ -2009,7 +2033,7 @@ pub fn graphgen_large_cohesive_fruchterman_reingold(c: &mut Criterion) { "graphgen_large_cohesive_fruchterman_reingold_subgraph", 20, 10, - large_random_attachment_subgraph, + small_random_attachment_subgraph, |graph, _| cohesive_fruchterman_reingold(graph, 5, 1.0, 1.0, 0.9, 0.1), ); graph_benchmark( @@ -2017,7 +2041,7 @@ pub fn graphgen_large_cohesive_fruchterman_reingold(c: &mut Criterion) { "graphgen_large_cohesive_fruchterman_reingold_layered", 20, 10, - large_random_attachment_layered, + small_random_attachment_layered, |graph, _| cohesive_fruchterman_reingold(graph, 5, 1.0, 1.0, 0.9, 0.1), ); graph_benchmark( @@ -2025,7 +2049,7 @@ pub fn graphgen_large_cohesive_fruchterman_reingold(c: &mut Criterion) { "graphgen_large_cohesive_fruchterman_reingold_graph_filtered", 20, 10, - large_random_attachment_filtered, + small_random_attachment_filtered, |graph, _| cohesive_fruchterman_reingold(graph, 5, 1.0, 1.0, 0.9, 0.1), ) } @@ -2071,7 +2095,7 @@ pub fn graphgen_large_max_weight_matching(c: &mut Criterion) { "graphgen_large_max_weight_matching", 20, 10, - large_random_attachment_graph, + small_random_attachment_graph, |graph, _| max_weight_matching(graph, None, false, false), ); graph_benchmark( @@ -2079,7 +2103,7 @@ pub fn graphgen_large_max_weight_matching(c: &mut Criterion) { "graphgen_large_max_weight_matching_subgraph", 20, 10, - large_random_attachment_subgraph, + small_random_attachment_subgraph, |graph, _| max_weight_matching(graph, None, false, false), ); graph_benchmark( @@ -2087,7 +2111,7 @@ pub fn graphgen_large_max_weight_matching(c: &mut Criterion) { "graphgen_large_max_weight_matching_layered", 20, 10, - large_random_attachment_layered, + small_random_attachment_layered, |graph, _| max_weight_matching(graph, None, false, false), ); graph_benchmark( @@ -2095,7 +2119,7 @@ pub fn graphgen_large_max_weight_matching(c: &mut Criterion) { "graphgen_large_max_weight_matching_graph_filtered", 20, 10, - large_random_attachment_filtered, + small_random_attachment_filtered, |graph, _| max_weight_matching(graph, None, false, false), ) } From 7d0f37cac690271e3b6a6ca58a0b9fc3974828d5 Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Mon, 3 Aug 2026 15:08:54 -0500 Subject: [PATCH 16/24] working on algo bench --- raphtory-benchmark/Cargo.toml | 10 +- raphtory-benchmark/benches/algobench.rs | 2304 ----------------- raphtory-benchmark/benches/algobench_fast.rs | 344 +++ .../benches/algobench_medium.rs | 386 +++ raphtory-benchmark/benches/algobench_slow.rs | 169 ++ raphtory-benchmark/src/algobench_common.rs | 284 ++ raphtory-benchmark/src/lib.rs | 1 + 7 files changed, 1193 insertions(+), 2305 deletions(-) delete mode 100644 raphtory-benchmark/benches/algobench.rs create mode 100644 raphtory-benchmark/benches/algobench_fast.rs create mode 100644 raphtory-benchmark/benches/algobench_medium.rs create mode 100644 raphtory-benchmark/benches/algobench_slow.rs create mode 100644 raphtory-benchmark/src/algobench_common.rs diff --git a/raphtory-benchmark/Cargo.toml b/raphtory-benchmark/Cargo.toml index 50db5fa3e3..6cc457d5de 100644 --- a/raphtory-benchmark/Cargo.toml +++ b/raphtory-benchmark/Cargo.toml @@ -45,7 +45,15 @@ name = "graph_ops" harness = false [[bench]] -name = "algobench" +name = "algobench_fast" +harness = false + +[[bench]] +name = "algobench_medium" +harness = false + +[[bench]] +name = "algobench_slow" harness = false [[bench]] diff --git a/raphtory-benchmark/benches/algobench.rs b/raphtory-benchmark/benches/algobench.rs deleted file mode 100644 index d9264eb830..0000000000 --- a/raphtory-benchmark/benches/algobench.rs +++ /dev/null @@ -1,2304 +0,0 @@ -use criterion::{criterion_group, criterion_main, Criterion, SamplingMode}; -use rand::{rngs::SmallRng, SeedableRng}; -use raphtory::{ - algorithms::{ - alternating_mask::alternating_mask, - bipartite::max_weight_matching::max_weight_matching, - centrality::{ - betweenness::betweenness_centrality, degree_centrality::degree_centrality, hits::hits, - pagerank::page_rank, - }, - community_detection::{ - label_propagation::label_propagation, louvain::louvain, modularity::ModularityUnDir, - }, - components::{ - in_component, in_component_filtered, in_components, in_components_filtered, - out_component, out_component_filtered, out_components, out_components_filtered, - strongly_connected_components, weakly_connected_components, - }, - cores::k_core::{k_core, k_core_set}, - dynamics::temporal::epidemics::{temporal_SEIR, Number}, - embeddings::fast_rp::fast_rp, - layout::{ - cohesive_fruchterman_reingold::cohesive_fruchterman_reingold, - fruchterman_reingold::fruchterman_reingold_unbounded, - }, - metrics::{ - balance::balance, - clustering_coefficient::{ - global_clustering_coefficient::global_clustering_coefficient, - local_clustering_coefficient::local_clustering_coefficient, - local_clustering_coefficient_batch::local_clustering_coefficient_batch, - }, - degree::{ - average_degree, max_degree, max_in_degree, max_out_degree, min_degree, - min_in_degree, min_out_degree, - }, - directed_graph_density::directed_graph_density, - reciprocity::{all_local_reciprocity, global_reciprocity}, - }, - motifs::{ - global_temporal_three_node_motifs::{ - global_temporal_three_node_motif, temporal_three_node_motif_multi, - triangle_motifs as global_triangle_motifs_internal, - }, - local_temporal_three_node_motifs::{ - temporal_three_node_motif as local_temporal_three_node_motif, - triangle_motifs as local_triangle_motifs_internal, - }, - local_triangle_count::local_triangle_count, - temporal_rich_club_coefficient::temporal_rich_club_coefficient, - three_node_motifs::{ - init_star_count, init_tri_count, init_two_node_count, new_triangle_edge, - star_event, two_node_event, - }, - triangle_count::triangle_count, - triplet_count::triplet_count, - }, - pathing::{ - dijkstra::dijkstra_single_source_shortest_paths, - single_source_shortest_path::single_source_shortest_path, - temporal_reachability::temporally_reachable_nodes, - }, - projections::temporal_bipartite_projection::temporal_bipartite_projection, - }, - db::{ - api::view::{Filter, StaticGraphViewOps}, - graph::views::{ - filter::{ - model::{ - degree_filter::DegreeFilterFactory, property_filter::ops::PropertyFilterOps, - }, - Unfiltered, - }, - node_subgraph::NodeSubgraph, - }, - }, - graphgen::random_attachment::random_attachment, - prelude::*, -}; -use raphtory_api::core::Direction; -use std::hint::black_box; - -fn graph_benchmark_with_setup( - c: &mut Criterion, - name: &str, - measurement_secs: u64, - sample_size: usize, - build_graph: BuildGraph, - setup: Setup, - mut run: Run, -) where - G: StaticGraphViewOps, - BuildGraph: FnOnce() -> G, - Setup: Fn(&G) -> SetupData, - Run: FnMut(&G, &SetupData) -> Output, -{ - let mut group = c.benchmark_group(name); - let graph = build_graph(); - let setup_data = setup(&graph); - - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(measurement_secs)); - group.sample_size(sample_size); - group.bench_function(name, |b| { - b.iter(|| { - let result = run(&graph, &setup_data); - black_box(result); - }); - }); - group.finish() -} - -fn graph_benchmark( - c: &mut Criterion, - name: &str, - measurement_secs: u64, - sample_size: usize, - build_graph: BuildGraph, - run: Run, -) where - G: StaticGraphViewOps, - BuildGraph: FnOnce() -> G, - Run: FnMut(&G, &()) -> Output, -{ - graph_benchmark_with_setup( - c, - name, - measurement_secs, - sample_size, - build_graph, - |_| (), - run, - ) -} - -fn simple_benchmark( - c: &mut Criterion, - name: &str, - measurement_secs: u64, - sample_size: usize, - mut run: Run, -) where - Run: FnMut() -> Output, -{ - let mut group = c.benchmark_group(name); - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(measurement_secs)); - group.sample_size(sample_size); - group.bench_function(name, |b| { - b.iter(|| { - let result = run(); - black_box(result); - }); - }); - group.finish() -} - -// Graph Constructors - -fn large_random_attachment_graph() -> Graph { - let graph = Graph::new(); - let seed: [u8; 32] = [1; 32]; - random_attachment(&graph, 5000, 4, Some(seed)); - graph -} - -fn large_random_attachment_subgraph() -> NodeSubgraph { - let graph = large_random_attachment_graph(); - let subgraph = graph.subgraph(graph.nodes()); - subgraph -} - -fn first_node_id(graph: &G) -> GID { - graph - .nodes() - .id() - .iter_values() - .next() - .expect("graph has nodes") -} - -fn large_weighted_random_attachment_graph() -> Graph { - let graph = large_random_attachment_graph(); - let ids = graph.nodes().id().iter_values().collect::>(); - if let (Some(src), Some(dst)) = (ids.first(), ids.get(1)) { - graph - .add_edge(0, src.clone(), dst.clone(), [("weight", 1.0f64)], None) - .expect("unable to add weighted edge"); - } - graph -} - -fn large_weighted_random_attachment_subgraph() -> NodeSubgraph { - let graph = large_weighted_random_attachment_graph(); - let subgraph = graph.subgraph(graph.nodes()); - subgraph -} - -fn large_random_attachment_filtered() -> impl StaticGraphViewOps { - large_random_attachment_graph() - .filter(NodeFilter.degree().ge(0u64)) - .unwrap() -} - -fn large_weighted_random_attachment_filtered() -> impl StaticGraphViewOps { - large_weighted_random_attachment_graph() - .filter(NodeFilter.degree().ge(0u64)) - .unwrap() -} - -fn large_typed_random_attachment_graph() -> Graph { - let graph = large_random_attachment_graph(); - for id in graph.nodes().id().iter_values() { - graph - .add_node(0, id, NO_PROPS, Some("Right"), None) - .expect("unable to set node type"); - } - graph -} - -fn large_typed_random_attachment_subgraph() -> NodeSubgraph { - let graph = large_typed_random_attachment_graph(); - let subgraph = graph.subgraph(graph.nodes()); - subgraph -} - -fn large_typed_random_attachment_filtered() -> impl StaticGraphViewOps { - large_typed_random_attachment_graph() - .filter(NodeFilter.degree().ge(0u64)) - .unwrap() -} - -fn large_random_attachment_layered() -> impl StaticGraphViewOps { - let graph = large_random_attachment_graph(); - graph.default_layer() -} - -fn large_weighted_random_attachment_layered() -> impl StaticGraphViewOps { - let graph = large_weighted_random_attachment_graph(); - graph.default_layer() -} - -fn large_typed_random_attachment_layered() -> impl StaticGraphViewOps { - let graph = large_typed_random_attachment_graph(); - graph.default_layer() -} - -fn small_random_attachment_graph() -> Graph { - let graph = Graph::new(); - let seed: [u8; 32] = [1; 32]; - random_attachment(&graph, 500, 4, Some(seed)); - graph -} - -fn small_random_attachment_subgraph() -> NodeSubgraph { - let graph = small_random_attachment_graph(); - let subgraph = graph.subgraph(graph.nodes()); - subgraph -} - -fn small_random_attachment_filtered() -> impl StaticGraphViewOps { - small_random_attachment_graph() - .filter(NodeFilter.degree().ge(0u64)) - .unwrap() -} - -fn small_random_attachment_layered() -> impl StaticGraphViewOps { - let graph = small_random_attachment_graph(); - graph.default_layer() -} - -// Benchmarks - -pub fn local_triangle_count_analysis(c: &mut Criterion) { - graph_benchmark_with_setup( - c, - "local_triangle_count", - 20, - 10, - large_random_attachment_graph, - first_node_id, - |graph, node_id| local_triangle_count(graph, node_id.clone()).unwrap(), - ); - - graph_benchmark_with_setup( - c, - "local_triangle_count_subgraph", - 20, - 10, - large_random_attachment_subgraph, - first_node_id, - |graph, node_id| local_triangle_count(graph, node_id.clone()).unwrap(), - ); - graph_benchmark_with_setup( - c, - "local_triangle_count_layered", - 20, - 10, - large_random_attachment_layered, - first_node_id, - |graph, node_id| local_triangle_count(graph, node_id.clone()).unwrap(), - ); - graph_benchmark_with_setup( - c, - "local_triangle_count_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - first_node_id, - |graph, node_id| local_triangle_count(graph, node_id.clone()).unwrap(), - ); -} - -pub fn local_clustering_coefficient_analysis(c: &mut Criterion) { - graph_benchmark_with_setup( - c, - "local_clustering_coefficient", - 20, - 10, - large_random_attachment_graph, - first_node_id, - |graph, node_id| local_clustering_coefficient(graph, node_id.clone()), - ); - graph_benchmark_with_setup( - c, - "local_clustering_coefficient_subgraph", - 20, - 10, - large_random_attachment_subgraph, - first_node_id, - |graph, node_id| local_clustering_coefficient(graph, node_id.clone()), - ); - graph_benchmark_with_setup( - c, - "local_clustering_coefficient_layered", - 20, - 10, - large_random_attachment_layered, - first_node_id, - |graph, node_id| local_clustering_coefficient(graph, node_id.clone()), - ); - graph_benchmark_with_setup( - c, - "local_clustering_coefficient_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - first_node_id, - |graph, node_id| local_clustering_coefficient(graph, node_id.clone()), - ) -} - -pub fn graphgen_large_clustering_coeff(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_clustering_coeff", - 60, - 10, - large_random_attachment_graph, - |graph, _| global_clustering_coefficient(graph), - ); - graph_benchmark( - c, - "graphgen_large_clustering_coeff_subgraph", - 60, - 10, - large_random_attachment_subgraph, - |graph, _| global_clustering_coefficient(graph), - ); - graph_benchmark( - c, - "graphgen_large_clustering_coeff_layered", - 60, - 10, - large_random_attachment_layered, - |graph, _| global_clustering_coefficient(graph), - ); - graph_benchmark( - c, - "graphgen_large_clustering_coeff_graph_filtered", - 60, - 10, - large_random_attachment_filtered, - |graph, _| global_clustering_coefficient(graph), - ) -} - -pub fn graphgen_large_pagerank(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_pagerank", - 20, - 10, - large_random_attachment_graph, - |graph, _| page_rank(graph, None, Some(100), None, None, true, None), - ); - graph_benchmark( - c, - "graphgen_large_pagerank_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| page_rank(graph, None, Some(100), None, None, true, None), - ); - graph_benchmark( - c, - "graphgen_large_pagerank_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| page_rank(graph, None, Some(100), None, None, true, None), - ); - graph_benchmark( - c, - "graphgen_large_pagerank_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| page_rank(graph, None, Some(100), None, None, true, None), - ) -} - -pub fn graphgen_large_concomp(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_concomp", - 60, - 10, - large_random_attachment_graph, - |graph, _| weakly_connected_components(graph), - ); - graph_benchmark( - c, - "graphgen_large_concomp_subgraph", - 60, - 10, - large_random_attachment_subgraph, - |graph, _| weakly_connected_components(graph), - ); - graph_benchmark( - c, - "graphgen_large_concomp_layered", - 60, - 10, - large_random_attachment_layered, - |graph, _| weakly_connected_components(graph), - ); - graph_benchmark( - c, - "graphgen_large_concomp_graph_filtered", - 60, - 10, - large_random_attachment_filtered, - |graph, _| weakly_connected_components(graph), - ) -} - -pub fn graphgen_large_hits(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_hits", - 20, - 10, - large_random_attachment_graph, - |graph, _| hits(graph, 100, None), - ); - graph_benchmark( - c, - "graphgen_large_hits_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| hits(graph, 100, None), - ); - graph_benchmark( - c, - "graphgen_large_hits_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| hits(graph, 100, None), - ); - graph_benchmark( - c, - "graphgen_large_hits_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| hits(graph, 100, None), - ) -} - -pub fn graphgen_large_degree_centrality(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_degree_centrality", - 20, - 10, - large_random_attachment_graph, - |graph, _| degree_centrality(graph), - ); - graph_benchmark( - c, - "graphgen_large_degree_centrality_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| degree_centrality(graph), - ); - graph_benchmark( - c, - "graphgen_large_degree_centrality_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| degree_centrality(graph), - ); - graph_benchmark( - c, - "graphgen_large_degree_centrality_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| degree_centrality(graph), - ) -} - -pub fn graphgen_large_betweenness(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_betweenness", - 20, - 10, - small_random_attachment_graph, - |graph, _| betweenness_centrality(graph, None, false), - ); - graph_benchmark( - c, - "graphgen_large_betweenness_subgraph", - 20, - 10, - small_random_attachment_subgraph, - |graph, _| betweenness_centrality(graph, None, false), - ); - graph_benchmark( - c, - "graphgen_large_betweenness_layered", - 20, - 10, - small_random_attachment_layered, - |graph, _| betweenness_centrality(graph, None, false), - ); - graph_benchmark( - c, - "graphgen_large_betweenness_graph_filtered", - 20, - 10, - small_random_attachment_filtered, - |graph, _| betweenness_centrality(graph, None, false), - ) -} - -pub fn graphgen_large_triangle_count(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_triangle_count", - 20, - 10, - large_random_attachment_graph, - |graph, _| triangle_count(graph, None), - ); - graph_benchmark( - c, - "graphgen_large_triangle_count_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| triangle_count(graph, None), - ); - graph_benchmark( - c, - "graphgen_large_triangle_count_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| triangle_count(graph, None), - ); - graph_benchmark( - c, - "graphgen_large_triangle_count_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| triangle_count(graph, None), - ) -} - -pub fn graphgen_large_triplet_count(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_triplet_count", - 20, - 10, - large_random_attachment_graph, - |graph, _| triplet_count(graph, None), - ); - graph_benchmark( - c, - "graphgen_large_triplet_count_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| triplet_count(graph, None), - ); - graph_benchmark( - c, - "graphgen_large_triplet_count_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| triplet_count(graph, None), - ); - graph_benchmark( - c, - "graphgen_large_triplet_count_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| triplet_count(graph, None), - ) -} - -pub fn graphgen_large_directed_density(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_directed_density", - 20, - 10, - large_random_attachment_graph, - |graph, _| directed_graph_density(graph), - ); - graph_benchmark( - c, - "graphgen_large_directed_density_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| directed_graph_density(graph), - ); - graph_benchmark( - c, - "graphgen_large_directed_density_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| directed_graph_density(graph), - ); - graph_benchmark( - c, - "graphgen_large_directed_density_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| directed_graph_density(graph), - ) -} - -pub fn graphgen_large_reciprocity(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_reciprocity", - 20, - 10, - large_random_attachment_graph, - |graph, _| global_reciprocity(graph), - ); - graph_benchmark( - c, - "graphgen_large_reciprocity_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| global_reciprocity(graph), - ); - graph_benchmark( - c, - "graphgen_large_reciprocity_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| global_reciprocity(graph), - ); - graph_benchmark( - c, - "graphgen_large_reciprocity_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| global_reciprocity(graph), - ) -} - -pub fn graphgen_large_scc(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_scc", - 20, - 10, - large_random_attachment_graph, - |graph, _| strongly_connected_components(graph), - ); - graph_benchmark( - c, - "graphgen_large_scc_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| strongly_connected_components(graph), - ); - graph_benchmark( - c, - "graphgen_large_scc_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| strongly_connected_components(graph), - ); - graph_benchmark( - c, - "graphgen_large_scc_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| strongly_connected_components(graph), - ) -} - -pub fn graphgen_large_in_components(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_in_components", - 20, - 10, - small_random_attachment_graph, - |graph, _| in_components(graph, None), - ); - graph_benchmark( - c, - "graphgen_large_in_components_subgraph", - 20, - 10, - small_random_attachment_subgraph, - |graph, _| in_components(graph, None), - ); - graph_benchmark( - c, - "graphgen_large_in_components_layered", - 20, - 10, - small_random_attachment_layered, - |graph, _| in_components(graph, None), - ); - graph_benchmark( - c, - "graphgen_large_in_components_graph_filtered", - 20, - 10, - small_random_attachment_filtered, - |graph, _| in_components(graph, None), - ) -} - -pub fn graphgen_large_out_components(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_out_components", - 20, - 10, - small_random_attachment_graph, - |graph, _| out_components(graph, None), - ); - graph_benchmark( - c, - "graphgen_large_out_components_subgraph", - 20, - 10, - small_random_attachment_subgraph, - |graph, _| out_components(graph, None), - ); - graph_benchmark( - c, - "graphgen_large_out_components_layered", - 20, - 10, - small_random_attachment_layered, - |graph, _| out_components(graph, None), - ); - graph_benchmark( - c, - "graphgen_large_out_components_graph_filtered", - 20, - 10, - small_random_attachment_filtered, - |graph, _| out_components(graph, None), - ) -} - -pub fn graphgen_large_in_components_filtered(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_in_components_filtered", - 20, - 10, - small_random_attachment_graph, - |graph, _| in_components_filtered(graph, None, Unfiltered).unwrap(), - ); - graph_benchmark( - c, - "graphgen_large_in_components_filtered_subgraph", - 20, - 10, - small_random_attachment_subgraph, - |graph, _| in_components_filtered(graph, None, Unfiltered).unwrap(), - ); - graph_benchmark( - c, - "graphgen_large_in_components_filtered_layered", - 20, - 10, - small_random_attachment_layered, - |graph, _| in_components_filtered(graph, None, Unfiltered).unwrap(), - ); - graph_benchmark( - c, - "graphgen_large_in_components_filtered_graph_filtered", - 20, - 10, - small_random_attachment_filtered, - |graph, _| in_components_filtered(graph, None, Unfiltered).unwrap(), - ) -} - -pub fn graphgen_large_out_components_filtered(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_out_components_filtered", - 20, - 10, - small_random_attachment_graph, - |graph, _| out_components_filtered(graph, None, Unfiltered).unwrap(), - ); - graph_benchmark( - c, - "graphgen_large_out_components_filtered_subgraph", - 20, - 10, - small_random_attachment_subgraph, - |graph, _| out_components_filtered(graph, None, Unfiltered).unwrap(), - ); - graph_benchmark( - c, - "graphgen_large_out_components_filtered_layered", - 20, - 10, - small_random_attachment_layered, - |graph, _| out_components_filtered(graph, None, Unfiltered).unwrap(), - ); - graph_benchmark( - c, - "graphgen_large_out_components_filtered_graph_filtered", - 20, - 10, - small_random_attachment_filtered, - |graph, _| out_components_filtered(graph, None, Unfiltered).unwrap(), - ) -} - -pub fn graphgen_large_label_propagation(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_label_propagation", - 20, - 10, - large_random_attachment_graph, - |graph, _| label_propagation(graph, 20, Some([1; 32]), None), - ); - graph_benchmark( - c, - "graphgen_large_label_propagation_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| label_propagation(graph, 20, Some([1; 32]), None), - ); - graph_benchmark( - c, - "graphgen_large_label_propagation_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| label_propagation(graph, 20, Some([1; 32]), None), - ); - graph_benchmark( - c, - "graphgen_large_label_propagation_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| label_propagation(graph, 20, Some([1; 32]), None), - ) -} - -pub fn graphgen_large_louvain(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_louvain", - 20, - 10, - large_random_attachment_graph, - |graph, _| louvain::(graph, 1.0, None, None, Some(42)), - ); - graph_benchmark( - c, - "graphgen_large_louvain_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| louvain::(graph, 1.0, None, None, Some(42)), - ); - graph_benchmark( - c, - "graphgen_large_louvain_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| louvain::(graph, 1.0, None, None, Some(42)), - ); - graph_benchmark( - c, - "graphgen_large_louvain_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| louvain::(graph, 1.0, None, None, Some(42)), - ) -} - -pub fn graphgen_large_alternating_mask(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_alternating_mask", - 20, - 10, - large_random_attachment_graph, - |graph, _| alternating_mask(graph), - ); - graph_benchmark( - c, - "graphgen_large_alternating_mask_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| alternating_mask(graph), - ); - graph_benchmark( - c, - "graphgen_large_alternating_mask_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| alternating_mask(graph), - ); - graph_benchmark( - c, - "graphgen_large_alternating_mask_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| alternating_mask(graph), - ) -} - -pub fn graphgen_large_all_local_reciprocity(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_all_local_reciprocity", - 20, - 10, - large_random_attachment_graph, - |graph, _| all_local_reciprocity(graph), - ); - graph_benchmark( - c, - "graphgen_large_all_local_reciprocity_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| all_local_reciprocity(graph), - ); - graph_benchmark( - c, - "graphgen_large_all_local_reciprocity_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| all_local_reciprocity(graph), - ); - graph_benchmark( - c, - "graphgen_large_all_local_reciprocity_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| all_local_reciprocity(graph), - ) -} - -pub fn graphgen_large_balance(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_balance", - 20, - 10, - large_weighted_random_attachment_graph, - |graph, _| balance(graph, "weight".to_string(), Direction::BOTH).unwrap(), - ); - graph_benchmark( - c, - "graphgen_large_balance_subgraph", - 20, - 10, - large_weighted_random_attachment_subgraph, - |graph, _| balance(graph, "weight".to_string(), Direction::BOTH).unwrap(), - ); - graph_benchmark( - c, - "graphgen_large_balance_layered", - 20, - 10, - large_weighted_random_attachment_layered, - |graph, _| balance(graph, "weight".to_string(), Direction::BOTH).unwrap(), - ); - graph_benchmark( - c, - "graphgen_large_balance_graph_filtered", - 20, - 10, - large_weighted_random_attachment_filtered, - |graph, _| balance(graph, "weight".to_string(), Direction::BOTH).unwrap(), - ) -} - -pub fn graphgen_large_max_degree(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_max_degree", - 20, - 10, - large_random_attachment_graph, - |graph, _| max_degree(graph), - ); - graph_benchmark( - c, - "graphgen_large_max_degree_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| max_degree(graph), - ); - graph_benchmark( - c, - "graphgen_large_max_degree_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| max_degree(graph), - ); - graph_benchmark( - c, - "graphgen_large_max_degree_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| max_degree(graph), - ) -} - -pub fn graphgen_large_min_degree(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_min_degree", - 20, - 10, - large_random_attachment_graph, - |graph, _| min_degree(graph), - ); - graph_benchmark( - c, - "graphgen_large_min_degree_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| min_degree(graph), - ); - graph_benchmark( - c, - "graphgen_large_min_degree_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| min_degree(graph), - ); - graph_benchmark( - c, - "graphgen_large_min_degree_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| min_degree(graph), - ) -} - -pub fn graphgen_large_max_out_degree(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_max_out_degree", - 20, - 10, - large_random_attachment_graph, - |graph, _| max_out_degree(graph), - ); - graph_benchmark( - c, - "graphgen_large_max_out_degree_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| max_out_degree(graph), - ); - graph_benchmark( - c, - "graphgen_large_max_out_degree_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| max_out_degree(graph), - ); - graph_benchmark( - c, - "graphgen_large_max_out_degree_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| max_out_degree(graph), - ) -} - -pub fn graphgen_large_max_in_degree(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_max_in_degree", - 20, - 10, - large_random_attachment_graph, - |graph, _| max_in_degree(graph), - ); - graph_benchmark( - c, - "graphgen_large_max_in_degree_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| max_in_degree(graph), - ); - graph_benchmark( - c, - "graphgen_large_max_in_degree_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| max_in_degree(graph), - ); - graph_benchmark( - c, - "graphgen_large_max_in_degree_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| max_in_degree(graph), - ) -} - -pub fn graphgen_large_min_out_degree(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_min_out_degree", - 20, - 10, - large_random_attachment_graph, - |graph, _| min_out_degree(graph), - ); - graph_benchmark( - c, - "graphgen_large_min_out_degree_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| min_out_degree(graph), - ); - graph_benchmark( - c, - "graphgen_large_min_out_degree_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| min_out_degree(graph), - ); - graph_benchmark( - c, - "graphgen_large_min_out_degree_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| min_out_degree(graph), - ) -} - -pub fn graphgen_large_min_in_degree(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_min_in_degree", - 20, - 10, - large_random_attachment_graph, - |graph, _| min_in_degree(graph), - ); - graph_benchmark( - c, - "graphgen_large_min_in_degree_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| min_in_degree(graph), - ); - graph_benchmark( - c, - "graphgen_large_min_in_degree_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| min_in_degree(graph), - ); - graph_benchmark( - c, - "graphgen_large_min_in_degree_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| min_in_degree(graph), - ) -} - -pub fn graphgen_large_average_degree(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_average_degree", - 20, - 10, - large_random_attachment_graph, - |graph, _| average_degree(graph), - ); - graph_benchmark( - c, - "graphgen_large_average_degree_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| average_degree(graph), - ); - graph_benchmark( - c, - "graphgen_large_average_degree_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| average_degree(graph), - ); - graph_benchmark( - c, - "graphgen_large_average_degree_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| average_degree(graph), - ) -} - -pub fn graphgen_large_local_clustering_coefficient_batch(c: &mut Criterion) { - graph_benchmark_with_setup( - c, - "graphgen_large_local_clustering_coefficient_batch", - 20, - 10, - large_random_attachment_graph, - first_node_id, - |graph, node_id| local_clustering_coefficient_batch(graph, vec![node_id.clone()]), - ); - graph_benchmark_with_setup( - c, - "graphgen_large_local_clustering_coefficient_batch_subgraph", - 20, - 10, - large_random_attachment_subgraph, - first_node_id, - |graph, node_id| local_clustering_coefficient_batch(graph, vec![node_id.clone()]), - ); - graph_benchmark_with_setup( - c, - "graphgen_large_local_clustering_coefficient_batch_layered", - 20, - 10, - large_random_attachment_layered, - first_node_id, - |graph, node_id| local_clustering_coefficient_batch(graph, vec![node_id.clone()]), - ); - graph_benchmark_with_setup( - c, - "graphgen_large_local_clustering_coefficient_batch_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - first_node_id, - |graph, node_id| local_clustering_coefficient_batch(graph, vec![node_id.clone()]), - ) -} - -pub fn graphgen_large_temporal_rich_club(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_temporal_rich_club", - 20, - 10, - small_random_attachment_graph, - |graph, _| { - let rolling = graph.rolling(1, Some(1)).unwrap(); - temporal_rich_club_coefficient(graph, rolling, 3, 3) - }, - ); - graph_benchmark( - c, - "graphgen_large_temporal_rich_club_subgraph", - 20, - 10, - small_random_attachment_subgraph, - |graph, _| { - let rolling = graph.rolling(1, Some(1)).unwrap(); - temporal_rich_club_coefficient(graph, rolling, 3, 3) - }, - ); - graph_benchmark( - c, - "graphgen_large_temporal_rich_club_layered", - 20, - 10, - small_random_attachment_layered, - |graph, _| { - let rolling = graph.rolling(1, Some(1)).unwrap(); - temporal_rich_club_coefficient(graph, rolling, 3, 3) - }, - ); - graph_benchmark( - c, - "graphgen_large_temporal_rich_club_graph_filtered", - 20, - 10, - small_random_attachment_filtered, - |graph, _| { - let rolling = graph.rolling(1, Some(1)).unwrap(); - temporal_rich_club_coefficient(graph, rolling, 3, 3) - }, - ) -} - -pub fn graphgen_large_temporal_motif_multi(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_temporal_motif_multi", - 20, - 10, - large_random_attachment_graph, - |graph, _| temporal_three_node_motif_multi(graph, vec![100], None), - ); - graph_benchmark( - c, - "graphgen_large_temporal_motif_multi_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| temporal_three_node_motif_multi(graph, vec![100], None), - ); - graph_benchmark( - c, - "graphgen_large_temporal_motif_multi_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| temporal_three_node_motif_multi(graph, vec![100], None), - ); - graph_benchmark( - c, - "graphgen_large_temporal_motif_multi_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| temporal_three_node_motif_multi(graph, vec![100], None), - ) -} - -pub fn graphgen_large_local_temporal_motif(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_local_temporal_motif", - 20, - 10, - large_random_attachment_graph, - |graph, _| local_temporal_three_node_motif(graph, 100, None), - ); - graph_benchmark( - c, - "graphgen_large_local_temporal_motif_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| local_temporal_three_node_motif(graph, 100, None), - ); - graph_benchmark( - c, - "graphgen_large_local_temporal_motif_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| local_temporal_three_node_motif(graph, 100, None), - ); - graph_benchmark( - c, - "graphgen_large_local_temporal_motif_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| local_temporal_three_node_motif(graph, 100, None), - ) -} - -pub fn graphgen_large_dijkstra(c: &mut Criterion) { - graph_benchmark_with_setup( - c, - "graphgen_large_dijkstra", - 20, - 10, - large_random_attachment_graph, - first_node_id, - |graph, source| { - dijkstra_single_source_shortest_paths( - graph, - source.clone(), - vec![source.clone()], - None, - Direction::BOTH, - ) - .unwrap() - }, - ); - graph_benchmark_with_setup( - c, - "graphgen_large_dijkstra_subgraph", - 20, - 10, - large_random_attachment_subgraph, - first_node_id, - |graph, source| { - dijkstra_single_source_shortest_paths( - graph, - source.clone(), - vec![source.clone()], - None, - Direction::BOTH, - ) - .unwrap() - }, - ); - graph_benchmark_with_setup( - c, - "graphgen_large_dijkstra_layered", - 20, - 10, - large_random_attachment_layered, - first_node_id, - |graph, source| { - dijkstra_single_source_shortest_paths( - graph, - source.clone(), - vec![source.clone()], - None, - Direction::BOTH, - ) - .unwrap() - }, - ); - graph_benchmark_with_setup( - c, - "graphgen_large_dijkstra_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - first_node_id, - |graph, source| { - dijkstra_single_source_shortest_paths( - graph, - source.clone(), - vec![source.clone()], - None, - Direction::BOTH, - ) - .unwrap() - }, - ) -} - -pub fn graphgen_large_single_source_shortest_path(c: &mut Criterion) { - graph_benchmark_with_setup( - c, - "graphgen_large_single_source_shortest_path", - 20, - 10, - large_random_attachment_graph, - first_node_id, - |graph, source| single_source_shortest_path(graph, source.clone(), None), - ); - graph_benchmark_with_setup( - c, - "graphgen_large_single_source_shortest_path_subgraph", - 20, - 10, - large_random_attachment_subgraph, - first_node_id, - |graph, source| single_source_shortest_path(graph, source.clone(), None), - ); - graph_benchmark_with_setup( - c, - "graphgen_large_single_source_shortest_path_layered", - 20, - 10, - large_random_attachment_layered, - first_node_id, - |graph, source| single_source_shortest_path(graph, source.clone(), None), - ); - graph_benchmark_with_setup( - c, - "graphgen_large_single_source_shortest_path_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - first_node_id, - |graph, source| single_source_shortest_path(graph, source.clone(), None), - ) -} - -pub fn graphgen_large_temporally_reachable_nodes(c: &mut Criterion) { - graph_benchmark_with_setup( - c, - "graphgen_large_temporally_reachable_nodes", - 20, - 10, - large_random_attachment_graph, - first_node_id, - |graph, source| temporally_reachable_nodes(graph, None, 20, 0, vec![source.clone()], None), - ); - graph_benchmark_with_setup( - c, - "graphgen_large_temporally_reachable_nodes_subgraph", - 20, - 10, - large_random_attachment_subgraph, - first_node_id, - |graph, source| temporally_reachable_nodes(graph, None, 20, 0, vec![source.clone()], None), - ); - graph_benchmark_with_setup( - c, - "graphgen_large_temporally_reachable_nodes_layered", - 20, - 10, - large_random_attachment_layered, - first_node_id, - |graph, source| temporally_reachable_nodes(graph, None, 20, 0, vec![source.clone()], None), - ); - graph_benchmark_with_setup( - c, - "graphgen_large_temporally_reachable_nodes_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - first_node_id, - |graph, source| temporally_reachable_nodes(graph, None, 20, 0, vec![source.clone()], None), - ) -} - -pub fn graphgen_large_in_component(c: &mut Criterion) { - graph_benchmark_with_setup( - c, - "graphgen_large_in_component", - 20, - 10, - large_random_attachment_graph, - first_node_id, - |graph, source| { - let node = graph.node(source.clone()).expect("source node exists"); - in_component(node) - }, - ); - graph_benchmark_with_setup( - c, - "graphgen_large_in_component_subgraph", - 20, - 10, - large_random_attachment_subgraph, - first_node_id, - |graph, source| { - let node = graph.node(source.clone()).expect("source node exists"); - in_component(node) - }, - ); - graph_benchmark_with_setup( - c, - "graphgen_large_in_component_layered", - 20, - 10, - large_random_attachment_layered, - first_node_id, - |graph, source| { - let node = graph.node(source.clone()).expect("source node exists"); - in_component(node) - }, - ); - graph_benchmark_with_setup( - c, - "graphgen_large_in_component_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - first_node_id, - |graph, source| { - let node = graph.node(source.clone()).expect("source node exists"); - in_component(node) - }, - ) -} - -pub fn graphgen_large_out_component(c: &mut Criterion) { - graph_benchmark_with_setup( - c, - "graphgen_large_out_component", - 20, - 10, - large_random_attachment_graph, - first_node_id, - |graph, source| { - let node = graph.node(source.clone()).expect("source node exists"); - out_component(node) - }, - ); - graph_benchmark_with_setup( - c, - "graphgen_large_out_component_subgraph", - 20, - 10, - large_random_attachment_subgraph, - first_node_id, - |graph, source| { - let node = graph.node(source.clone()).expect("source node exists"); - out_component(node) - }, - ); - graph_benchmark_with_setup( - c, - "graphgen_large_out_component_layered", - 20, - 10, - large_random_attachment_layered, - first_node_id, - |graph, source| { - let node = graph.node(source.clone()).expect("source node exists"); - out_component(node) - }, - ); - graph_benchmark_with_setup( - c, - "graphgen_large_out_component_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - first_node_id, - |graph, source| { - let node = graph.node(source.clone()).expect("source node exists"); - out_component(node) - }, - ) -} - -pub fn graphgen_large_in_component_filtered(c: &mut Criterion) { - graph_benchmark_with_setup( - c, - "graphgen_large_in_component_filtered", - 20, - 10, - large_random_attachment_graph, - first_node_id, - |graph, source| { - let node = graph.node(source.clone()).expect("source node exists"); - in_component_filtered(node, Unfiltered).unwrap() - }, - ); - graph_benchmark_with_setup( - c, - "graphgen_large_in_component_filtered_subgraph", - 20, - 10, - large_random_attachment_subgraph, - first_node_id, - |graph, source| { - let node = graph.node(source.clone()).expect("source node exists"); - in_component_filtered(node, Unfiltered).unwrap() - }, - ); - graph_benchmark_with_setup( - c, - "graphgen_large_in_component_filtered_layered", - 20, - 10, - large_random_attachment_layered, - first_node_id, - |graph, source| { - let node = graph.node(source.clone()).expect("source node exists"); - in_component_filtered(node, Unfiltered).unwrap() - }, - ); - graph_benchmark_with_setup( - c, - "graphgen_large_in_component_filtered_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - first_node_id, - |graph, source| { - let node = graph.node(source.clone()).expect("source node exists"); - in_component_filtered(node, Unfiltered).unwrap() - }, - ) -} - -pub fn graphgen_large_out_component_filtered(c: &mut Criterion) { - graph_benchmark_with_setup( - c, - "graphgen_large_out_component_filtered", - 20, - 10, - large_random_attachment_graph, - first_node_id, - |graph, source| { - let node = graph.node(source.clone()).expect("source node exists"); - out_component_filtered(node, Unfiltered).unwrap() - }, - ); - graph_benchmark_with_setup( - c, - "graphgen_large_out_component_filtered_subgraph", - 20, - 10, - large_random_attachment_subgraph, - first_node_id, - |graph, source| { - let node = graph.node(source.clone()).expect("source node exists"); - out_component_filtered(node, Unfiltered).unwrap() - }, - ); - graph_benchmark_with_setup( - c, - "graphgen_large_out_component_filtered_layered", - 20, - 10, - large_random_attachment_layered, - first_node_id, - |graph, source| { - let node = graph.node(source.clone()).expect("source node exists"); - out_component_filtered(node, Unfiltered).unwrap() - }, - ); - graph_benchmark_with_setup( - c, - "graphgen_large_out_component_filtered_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - first_node_id, - |graph, source| { - let node = graph.node(source.clone()).expect("source node exists"); - out_component_filtered(node, Unfiltered).unwrap() - }, - ) -} - -pub fn graphgen_internal_two_node_event(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_two_node_event", 20, 10, || { - two_node_event(1, 100) - }) -} - -pub fn graphgen_internal_init_two_node_count(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_init_two_node_count", 20, 10, || { - init_two_node_count() - }) -} - -pub fn graphgen_internal_star_event(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_star_event", 20, 10, || { - star_event(0, 1, 100) - }) -} - -pub fn graphgen_internal_init_star_count(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_init_star_count", 20, 10, || { - init_star_count(128) - }) -} - -pub fn graphgen_internal_new_triangle_edge(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_new_triangle_edge", 20, 10, || { - new_triangle_edge(true, 1, 0, 1, 100) - }) -} - -pub fn graphgen_internal_init_tri_count(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_init_tri_count", 20, 10, || { - init_tri_count(128) - }) -} - -pub fn graphgen_internal_global_triangle_motifs(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_internal_global_triangle_motifs", - 20, - 10, - large_random_attachment_graph, - |graph, _| global_triangle_motifs_internal(graph, vec![100], None), - ); - graph_benchmark( - c, - "graphgen_internal_global_triangle_motifs_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| global_triangle_motifs_internal(graph, vec![100], None), - ); - graph_benchmark( - c, - "graphgen_internal_global_triangle_motifs_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| global_triangle_motifs_internal(graph, vec![100], None), - ); - graph_benchmark( - c, - "graphgen_internal_global_triangle_motifs_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| global_triangle_motifs_internal(graph, vec![100], None), - ) -} - -pub fn graphgen_internal_local_triangle_motifs(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_internal_local_triangle_motifs", - 20, - 10, - large_random_attachment_graph, - |graph, _| local_triangle_motifs_internal(graph, vec![100], None), - ); - graph_benchmark( - c, - "graphgen_internal_local_triangle_motifs_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| local_triangle_motifs_internal(graph, vec![100], None), - ); - graph_benchmark( - c, - "graphgen_internal_local_triangle_motifs_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| local_triangle_motifs_internal(graph, vec![100], None), - ); - graph_benchmark( - c, - "graphgen_internal_local_triangle_motifs_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| local_triangle_motifs_internal(graph, vec![100], None), - ) -} - -pub fn graphgen_large_k_core_set(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_k_core_set", - 20, - 10, - large_random_attachment_graph, - |graph, _| k_core_set(graph, 2, usize::MAX, None), - ); - graph_benchmark( - c, - "graphgen_large_k_core_set_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| k_core_set(graph, 2, usize::MAX, None), - ); - graph_benchmark( - c, - "graphgen_large_k_core_set_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| k_core_set(graph, 2, usize::MAX, None), - ); - graph_benchmark( - c, - "graphgen_large_k_core_set_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| k_core_set(graph, 2, usize::MAX, None), - ) -} - -pub fn graphgen_large_k_core(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_k_core", - 20, - 10, - large_random_attachment_graph, - |graph, _| k_core(graph, 2, usize::MAX, None), - ); - graph_benchmark( - c, - "graphgen_large_k_core_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| k_core(graph, 2, usize::MAX, None), - ); - graph_benchmark( - c, - "graphgen_large_k_core_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| k_core(graph, 2, usize::MAX, None), - ); - graph_benchmark( - c, - "graphgen_large_k_core_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| k_core(graph, 2, usize::MAX, None), - ) -} - -pub fn graphgen_large_fruchterman_reingold(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_fruchterman_reingold", - 20, - 10, - small_random_attachment_graph, - |graph, _| fruchterman_reingold_unbounded(graph, 5, 1.0, 1.0, 0.9, 0.1), - ); - graph_benchmark( - c, - "graphgen_large_fruchterman_reingold_subgraph", - 20, - 10, - small_random_attachment_subgraph, - |graph, _| fruchterman_reingold_unbounded(graph, 5, 1.0, 1.0, 0.9, 0.1), - ); - graph_benchmark( - c, - "graphgen_large_fruchterman_reingold_layered", - 20, - 10, - small_random_attachment_layered, - |graph, _| fruchterman_reingold_unbounded(graph, 5, 1.0, 1.0, 0.9, 0.1), - ); - graph_benchmark( - c, - "graphgen_large_fruchterman_reingold_graph_filtered", - 20, - 10, - small_random_attachment_filtered, - |graph, _| fruchterman_reingold_unbounded(graph, 5, 1.0, 1.0, 0.9, 0.1), - ) -} - -pub fn graphgen_large_cohesive_fruchterman_reingold(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_cohesive_fruchterman_reingold", - 20, - 10, - small_random_attachment_graph, - |graph, _| cohesive_fruchterman_reingold(graph, 5, 1.0, 1.0, 0.9, 0.1), - ); - graph_benchmark( - c, - "graphgen_large_cohesive_fruchterman_reingold_subgraph", - 20, - 10, - small_random_attachment_subgraph, - |graph, _| cohesive_fruchterman_reingold(graph, 5, 1.0, 1.0, 0.9, 0.1), - ); - graph_benchmark( - c, - "graphgen_large_cohesive_fruchterman_reingold_layered", - 20, - 10, - small_random_attachment_layered, - |graph, _| cohesive_fruchterman_reingold(graph, 5, 1.0, 1.0, 0.9, 0.1), - ); - graph_benchmark( - c, - "graphgen_large_cohesive_fruchterman_reingold_graph_filtered", - 20, - 10, - small_random_attachment_filtered, - |graph, _| cohesive_fruchterman_reingold(graph, 5, 1.0, 1.0, 0.9, 0.1), - ) -} - -pub fn graphgen_large_fast_rp(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_fast_rp", - 20, - 10, - large_random_attachment_graph, - |graph, _| fast_rp(graph, 32, 0.5, vec![1.0, 1.0, 1.0], Some(1), None), - ); - graph_benchmark( - c, - "graphgen_large_fast_rp_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| fast_rp(graph, 32, 0.5, vec![1.0, 1.0, 1.0], Some(1), None), - ); - graph_benchmark( - c, - "graphgen_large_fast_rp_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| fast_rp(graph, 32, 0.5, vec![1.0, 1.0, 1.0], Some(1), None), - ); - graph_benchmark( - c, - "graphgen_large_fast_rp_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| fast_rp(graph, 32, 0.5, vec![1.0, 1.0, 1.0], Some(1), None), - ) -} - -pub fn graphgen_large_max_weight_matching(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_max_weight_matching", - 20, - 10, - small_random_attachment_graph, - |graph, _| max_weight_matching(graph, None, false, false), - ); - graph_benchmark( - c, - "graphgen_large_max_weight_matching_subgraph", - 20, - 10, - small_random_attachment_subgraph, - |graph, _| max_weight_matching(graph, None, false, false), - ); - graph_benchmark( - c, - "graphgen_large_max_weight_matching_layered", - 20, - 10, - small_random_attachment_layered, - |graph, _| max_weight_matching(graph, None, false, false), - ); - graph_benchmark( - c, - "graphgen_large_max_weight_matching_graph_filtered", - 20, - 10, - small_random_attachment_filtered, - |graph, _| max_weight_matching(graph, None, false, false), - ) -} - -pub fn graphgen_large_temporal_seir(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_temporal_seir", - 20, - 10, - large_random_attachment_graph, - |graph, _| { - let mut rng = SmallRng::seed_from_u64(1); - temporal_SEIR(graph, Some(0.1), None, 0.5f64, 0, Number(1), &mut rng).unwrap() - }, - ); - graph_benchmark( - c, - "graphgen_large_temporal_seir_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| { - let mut rng = SmallRng::seed_from_u64(1); - temporal_SEIR(graph, Some(0.1), None, 0.5f64, 0, Number(1), &mut rng).unwrap() - }, - ); - graph_benchmark( - c, - "graphgen_large_temporal_seir_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| { - let mut rng = SmallRng::seed_from_u64(1); - temporal_SEIR(graph, Some(0.1), None, 0.5f64, 0, Number(1), &mut rng).unwrap() - }, - ); - graph_benchmark( - c, - "graphgen_large_temporal_seir_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| { - let mut rng = SmallRng::seed_from_u64(1); - temporal_SEIR(graph, Some(0.1), None, 0.5f64, 0, Number(1), &mut rng).unwrap() - }, - ) -} - -pub fn graphgen_large_temporal_bipartite_projection(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_large_temporal_bipartite_projection", - 20, - 10, - large_typed_random_attachment_graph, - |graph, _| temporal_bipartite_projection(graph, 1, "Right".to_string()), - ); - graph_benchmark( - c, - "graphgen_large_temporal_bipartite_projection_subgraph", - 20, - 10, - large_typed_random_attachment_subgraph, - |graph, _| temporal_bipartite_projection(graph, 1, "Right".to_string()), - ); - graph_benchmark( - c, - "graphgen_large_temporal_bipartite_projection_layered", - 20, - 10, - large_typed_random_attachment_layered, - |graph, _| temporal_bipartite_projection(graph, 1, "Right".to_string()), - ); - graph_benchmark( - c, - "graphgen_large_temporal_bipartite_projection_graph_filtered", - 20, - 10, - large_typed_random_attachment_filtered, - |graph, _| temporal_bipartite_projection(graph, 1, "Right".to_string()), - ) -} - -pub fn temporal_motifs(c: &mut Criterion) { - graph_benchmark( - c, - "temporal_motifs", - 20, - 10, - large_random_attachment_graph, - |graph, _| global_temporal_three_node_motif(graph, 100, None), - ); - graph_benchmark( - c, - "temporal_motifs_subgraph", - 20, - 10, - large_random_attachment_subgraph, - |graph, _| global_temporal_three_node_motif(graph, 100, None), - ); - graph_benchmark( - c, - "temporal_motifs_layered", - 20, - 10, - large_random_attachment_layered, - |graph, _| global_temporal_three_node_motif(graph, 100, None), - ); - graph_benchmark( - c, - "temporal_motifs_graph_filtered", - 20, - 10, - large_random_attachment_filtered, - |graph, _| global_temporal_three_node_motif(graph, 100, None), - ) -} - -criterion_group!( - benches, - local_triangle_count_analysis, - local_clustering_coefficient_analysis, - graphgen_large_clustering_coeff, - graphgen_large_pagerank, - graphgen_large_concomp, - graphgen_large_hits, - graphgen_large_degree_centrality, - graphgen_large_betweenness, - graphgen_large_triangle_count, - graphgen_large_triplet_count, - graphgen_large_directed_density, - graphgen_large_reciprocity, - graphgen_large_scc, - graphgen_large_in_components, - graphgen_large_out_components, - graphgen_large_in_components_filtered, - graphgen_large_out_components_filtered, - graphgen_large_label_propagation, - graphgen_large_louvain, - graphgen_large_alternating_mask, - graphgen_large_all_local_reciprocity, - graphgen_large_balance, - graphgen_large_max_degree, - graphgen_large_min_degree, - graphgen_large_max_out_degree, - graphgen_large_max_in_degree, - graphgen_large_min_out_degree, - graphgen_large_min_in_degree, - graphgen_large_average_degree, - graphgen_large_local_clustering_coefficient_batch, - graphgen_large_temporal_rich_club, - graphgen_large_temporal_motif_multi, - graphgen_large_local_temporal_motif, - graphgen_large_dijkstra, - graphgen_large_single_source_shortest_path, - graphgen_large_temporally_reachable_nodes, - graphgen_large_in_component, - graphgen_large_out_component, - graphgen_large_in_component_filtered, - graphgen_large_out_component_filtered, - graphgen_large_k_core_set, - graphgen_large_k_core, - graphgen_large_fruchterman_reingold, - graphgen_large_cohesive_fruchterman_reingold, - graphgen_large_fast_rp, - graphgen_large_max_weight_matching, - graphgen_large_temporal_seir, - graphgen_large_temporal_bipartite_projection, - graphgen_internal_two_node_event, - graphgen_internal_init_two_node_count, - graphgen_internal_star_event, - graphgen_internal_init_star_count, - graphgen_internal_new_triangle_edge, - graphgen_internal_init_tri_count, - graphgen_internal_global_triangle_motifs, - graphgen_internal_local_triangle_motifs, - temporal_motifs, -); -criterion_main!(benches); diff --git a/raphtory-benchmark/benches/algobench_fast.rs b/raphtory-benchmark/benches/algobench_fast.rs new file mode 100644 index 0000000000..1e2e4aecc8 --- /dev/null +++ b/raphtory-benchmark/benches/algobench_fast.rs @@ -0,0 +1,344 @@ +// Trivial / fast algorithms (sub-millisecond to ~1ms on the 5000-node large graph). +// +// `directed_graph_density` is this binary's representative for graph/subgraph/layered/filtered +// view coverage; every other algorithm here only benchmarks the plain graph. + +use raphtory::{ + algorithms::{ + alternating_mask::alternating_mask, + centrality::degree_centrality::degree_centrality, + components::{out_component, out_component_filtered}, + metrics::{ + clustering_coefficient::{ + local_clustering_coefficient::local_clustering_coefficient, + local_clustering_coefficient_batch::local_clustering_coefficient_batch, + }, + degree::{ + average_degree, max_degree, max_in_degree, max_out_degree, min_degree, + min_in_degree, min_out_degree, + }, + directed_graph_density::directed_graph_density, + }, + motifs::{ + local_triangle_count::local_triangle_count, + three_node_motifs::{ + init_star_count, init_tri_count, init_two_node_count, new_triangle_edge, + star_event, two_node_event, + }, + }, + pathing::temporal_reachability::temporally_reachable_nodes, + components::weakly_connected_components, + dynamics::temporal::epidemics::{temporal_SEIR, Number}, + }, + db::graph::views::filter::Unfiltered, + prelude::*, +}; +use criterion::{criterion_group, criterion_main, Criterion}; +use rand::{rngs::SmallRng, SeedableRng}; +use raphtory_benchmark::algobench_common::{ + first_node_id, graph_benchmark, graph_benchmark_with_setup, large_random_attachment_filtered, + large_random_attachment_graph, large_random_attachment_layered, + large_random_attachment_subgraph, simple_benchmark, +}; + +pub fn local_triangle_count_analysis(c: &mut Criterion) { + graph_benchmark_with_setup( + c, + "local_triangle_count", + 3, + 10, + large_random_attachment_graph, + first_node_id, + |graph, node_id| local_triangle_count(graph, node_id.clone()).unwrap(), + ); +} + +pub fn local_clustering_coefficient_analysis(c: &mut Criterion) { + graph_benchmark_with_setup( + c, + "local_clustering_coefficient", + 3, + 10, + large_random_attachment_graph, + first_node_id, + |graph, node_id| local_clustering_coefficient(graph, node_id.clone()), + ); +} + +pub fn graphgen_large_directed_density(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_directed_density", + 2, + 10, + large_random_attachment_graph, + |graph, _| directed_graph_density(graph), + ); + graph_benchmark( + c, + "graphgen_large_directed_density_subgraph", + 3, + 10, + large_random_attachment_subgraph, + |graph, _| directed_graph_density(graph), + ); + graph_benchmark( + c, + "graphgen_large_directed_density_layered", + 3, + 10, + large_random_attachment_layered, + |graph, _| directed_graph_density(graph), + ); + graph_benchmark( + c, + "graphgen_large_directed_density_graph_filtered", + 5, + 10, + large_random_attachment_filtered, + |graph, _| directed_graph_density(graph), + ) +} + +pub fn graphgen_large_degree_centrality(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_degree_centrality", + 3, + 10, + large_random_attachment_graph, + |graph, _| degree_centrality(graph), + ); +} + +pub fn graphgen_large_concomp(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_concomp", + 5, + 10, + large_random_attachment_graph, + |graph, _| weakly_connected_components(graph), + ); +} + +pub fn graphgen_large_alternating_mask(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_alternating_mask", + 3, + 10, + large_random_attachment_graph, + |graph, _| alternating_mask(graph), + ); +} + +pub fn graphgen_large_max_degree(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_max_degree", + 3, + 10, + large_random_attachment_graph, + |graph, _| max_degree(graph), + ); +} + +pub fn graphgen_large_min_degree(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_min_degree", + 3, + 10, + large_random_attachment_graph, + |graph, _| min_degree(graph), + ); +} + +pub fn graphgen_large_max_out_degree(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_max_out_degree", + 3, + 10, + large_random_attachment_graph, + |graph, _| max_out_degree(graph), + ); +} + +pub fn graphgen_large_max_in_degree(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_max_in_degree", + 3, + 10, + large_random_attachment_graph, + |graph, _| max_in_degree(graph), + ); +} + +pub fn graphgen_large_min_out_degree(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_min_out_degree", + 3, + 10, + large_random_attachment_graph, + |graph, _| min_out_degree(graph), + ); +} + +pub fn graphgen_large_min_in_degree(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_min_in_degree", + 3, + 10, + large_random_attachment_graph, + |graph, _| min_in_degree(graph), + ); +} + +pub fn graphgen_large_average_degree(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_average_degree", + 3, + 10, + large_random_attachment_graph, + |graph, _| average_degree(graph), + ); +} + +pub fn graphgen_large_local_clustering_coefficient_batch(c: &mut Criterion) { + graph_benchmark_with_setup( + c, + "graphgen_large_local_clustering_coefficient_batch", + 3, + 10, + large_random_attachment_graph, + first_node_id, + |graph, node_id| local_clustering_coefficient_batch(graph, vec![node_id.clone()]), + ); +} + +pub fn graphgen_large_temporally_reachable_nodes(c: &mut Criterion) { + graph_benchmark_with_setup( + c, + "graphgen_large_temporally_reachable_nodes", + 3, + 10, + large_random_attachment_graph, + first_node_id, + |graph, source| temporally_reachable_nodes(graph, None, 20, 0, vec![source.clone()], None), + ); +} + +pub fn graphgen_large_out_component(c: &mut Criterion) { + graph_benchmark_with_setup( + c, + "graphgen_large_out_component", + 3, + 10, + large_random_attachment_graph, + first_node_id, + |graph, source| { + let node = graph.node(source.clone()).expect("source node exists"); + out_component(node) + }, + ); +} + +pub fn graphgen_large_out_component_filtered(c: &mut Criterion) { + graph_benchmark_with_setup( + c, + "graphgen_large_out_component_filtered", + 3, + 10, + large_random_attachment_graph, + first_node_id, + |graph, source| { + let node = graph.node(source.clone()).expect("source node exists"); + out_component_filtered(node, Unfiltered).unwrap() + }, + ); +} + +pub fn graphgen_large_temporal_seir(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_temporal_seir", + 3, + 10, + large_random_attachment_graph, + |graph, _| { + let mut rng = SmallRng::seed_from_u64(1); + temporal_SEIR(graph, Some(0.1), None, 0.5f64, 0, Number(1), &mut rng).unwrap() + }, + ); +} + +pub fn graphgen_internal_two_node_event(c: &mut Criterion) { + simple_benchmark(c, "graphgen_internal_two_node_event", 2, 10, || { + two_node_event(1, 100) + }) +} + +pub fn graphgen_internal_init_two_node_count(c: &mut Criterion) { + simple_benchmark(c, "graphgen_internal_init_two_node_count", 2, 10, || { + init_two_node_count() + }) +} + +pub fn graphgen_internal_star_event(c: &mut Criterion) { + simple_benchmark(c, "graphgen_internal_star_event", 2, 10, || { + star_event(0, 1, 100) + }) +} + +pub fn graphgen_internal_init_star_count(c: &mut Criterion) { + simple_benchmark(c, "graphgen_internal_init_star_count", 2, 10, || { + init_star_count(128) + }) +} + +pub fn graphgen_internal_new_triangle_edge(c: &mut Criterion) { + simple_benchmark(c, "graphgen_internal_new_triangle_edge", 2, 10, || { + new_triangle_edge(true, 1, 0, 1, 100) + }) +} + +pub fn graphgen_internal_init_tri_count(c: &mut Criterion) { + simple_benchmark(c, "graphgen_internal_init_tri_count", 2, 10, || { + init_tri_count(128) + }) +} + +criterion_group!( + benches, + local_triangle_count_analysis, + local_clustering_coefficient_analysis, + graphgen_large_directed_density, + graphgen_large_degree_centrality, + graphgen_large_concomp, + graphgen_large_alternating_mask, + graphgen_large_max_degree, + graphgen_large_min_degree, + graphgen_large_max_out_degree, + graphgen_large_max_in_degree, + graphgen_large_min_out_degree, + graphgen_large_min_in_degree, + graphgen_large_average_degree, + graphgen_large_local_clustering_coefficient_batch, + graphgen_large_temporally_reachable_nodes, + graphgen_large_out_component, + graphgen_large_out_component_filtered, + graphgen_large_temporal_seir, + graphgen_internal_two_node_event, + graphgen_internal_init_two_node_count, + graphgen_internal_star_event, + graphgen_internal_init_star_count, + graphgen_internal_new_triangle_edge, + graphgen_internal_init_tri_count, +); +criterion_main!(benches); diff --git a/raphtory-benchmark/benches/algobench_medium.rs b/raphtory-benchmark/benches/algobench_medium.rs new file mode 100644 index 0000000000..f036c0403a --- /dev/null +++ b/raphtory-benchmark/benches/algobench_medium.rs @@ -0,0 +1,386 @@ +// Medium complexity algorithms (roughly ~1ms - 200ms), run against a dedicated 1500-node +// medium graph rather than the large (5000 node) or tiny (100 node) graphs used by the +// fast/slow tiers. +// +// `pagerank` is this binary's representative for graph/subgraph/layered/filtered view +// coverage; every other algorithm here only benchmarks the plain graph. + +use raphtory::{ + algorithms::{ + centrality::{hits::hits, pagerank::page_rank}, + community_detection::{ + label_propagation::label_propagation, louvain::louvain, modularity::ModularityUnDir, + }, + components::{in_component, in_component_filtered, strongly_connected_components}, + cores::k_core::{k_core, k_core_set}, + embeddings::fast_rp::fast_rp, + metrics::{ + balance::balance, + clustering_coefficient::global_clustering_coefficient::global_clustering_coefficient, + reciprocity::{all_local_reciprocity, global_reciprocity}, + }, + motifs::{ + global_temporal_three_node_motifs::{ + global_temporal_three_node_motif, temporal_three_node_motif_multi, + triangle_motifs as global_triangle_motifs_internal, + }, + local_temporal_three_node_motifs::{ + temporal_three_node_motif as local_temporal_three_node_motif, + triangle_motifs as local_triangle_motifs_internal, + }, + triangle_count::triangle_count, + triplet_count::triplet_count, + }, + pathing::{ + dijkstra::dijkstra_single_source_shortest_paths, + single_source_shortest_path::single_source_shortest_path, + }, + projections::temporal_bipartite_projection::temporal_bipartite_projection, + }, + db::graph::views::filter::Unfiltered, + prelude::*, +}; +use criterion::{criterion_group, criterion_main, Criterion}; +use raphtory_api::core::Direction; +use raphtory_benchmark::algobench_common::{ + first_node_id, graph_benchmark, graph_benchmark_with_setup, medium_random_attachment_filtered, + medium_random_attachment_graph, medium_random_attachment_layered, + medium_random_attachment_subgraph, medium_typed_random_attachment_graph, + medium_weighted_random_attachment_graph, +}; + +pub fn graphgen_medium_clustering_coeff(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_medium_clustering_coeff", + 10, + 10, + medium_random_attachment_graph, + |graph, _| global_clustering_coefficient(graph), + ); +} + +pub fn graphgen_medium_pagerank(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_medium_pagerank", + 10, + 10, + medium_random_attachment_graph, + |graph, _| page_rank(graph, None, Some(100), None, None, true, None), + ); + graph_benchmark( + c, + "graphgen_medium_pagerank_subgraph", + 10, + 10, + medium_random_attachment_subgraph, + |graph, _| page_rank(graph, None, Some(100), None, None, true, None), + ); + graph_benchmark( + c, + "graphgen_medium_pagerank_layered", + 10, + 10, + medium_random_attachment_layered, + |graph, _| page_rank(graph, None, Some(100), None, None, true, None), + ); + graph_benchmark( + c, + "graphgen_medium_pagerank_graph_filtered", + 20, + 10, + medium_random_attachment_filtered, + |graph, _| page_rank(graph, None, Some(100), None, None, true, None), + ) +} + +pub fn graphgen_medium_hits(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_medium_hits", + 5, + 10, + medium_random_attachment_graph, + |graph, _| hits(graph, 100, None), + ); +} + +pub fn graphgen_medium_triangle_count(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_medium_triangle_count", + 10, + 10, + medium_random_attachment_graph, + |graph, _| triangle_count(graph, None), + ); +} + +pub fn graphgen_medium_triplet_count(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_medium_triplet_count", + 5, + 10, + medium_random_attachment_graph, + |graph, _| triplet_count(graph, None), + ); +} + +pub fn graphgen_medium_reciprocity(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_medium_reciprocity", + 5, + 10, + medium_random_attachment_graph, + |graph, _| global_reciprocity(graph), + ); +} + +pub fn graphgen_medium_scc(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_medium_scc", + 5, + 10, + medium_random_attachment_graph, + |graph, _| strongly_connected_components(graph), + ); +} + +pub fn graphgen_medium_label_propagation(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_medium_label_propagation", + 20, + 10, + medium_random_attachment_graph, + |graph, _| label_propagation(graph, 20, Some([1; 32]), None), + ); +} + +pub fn graphgen_medium_louvain(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_medium_louvain", + 20, + 10, + medium_random_attachment_graph, + |graph, _| louvain::(graph, 1.0, None, None, Some(42)), + ); +} + +pub fn graphgen_medium_all_local_reciprocity(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_medium_all_local_reciprocity", + 5, + 10, + medium_random_attachment_graph, + |graph, _| all_local_reciprocity(graph), + ); +} + +pub fn graphgen_medium_balance(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_medium_balance", + 5, + 10, + medium_weighted_random_attachment_graph, + |graph, _| balance(graph, "weight".to_string(), Direction::BOTH).unwrap(), + ); +} + +pub fn graphgen_medium_temporal_motif_multi(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_medium_temporal_motif_multi", + 20, + 10, + medium_random_attachment_graph, + |graph, _| temporal_three_node_motif_multi(graph, vec![100], None), + ); +} + +pub fn graphgen_medium_local_temporal_motif(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_medium_local_temporal_motif", + 20, + 10, + medium_random_attachment_graph, + |graph, _| local_temporal_three_node_motif(graph, 100, None), + ); +} + +pub fn graphgen_medium_dijkstra(c: &mut Criterion) { + graph_benchmark_with_setup( + c, + "graphgen_medium_dijkstra", + 5, + 10, + medium_random_attachment_graph, + first_node_id, + |graph, source| { + dijkstra_single_source_shortest_paths( + graph, + source.clone(), + vec![source.clone()], + None, + Direction::BOTH, + ) + .unwrap() + }, + ); +} + +pub fn graphgen_medium_single_source_shortest_path(c: &mut Criterion) { + graph_benchmark_with_setup( + c, + "graphgen_medium_single_source_shortest_path", + 5, + 10, + medium_random_attachment_graph, + first_node_id, + |graph, source| single_source_shortest_path(graph, source.clone(), None), + ); +} + +pub fn graphgen_medium_in_component(c: &mut Criterion) { + graph_benchmark_with_setup( + c, + "graphgen_medium_in_component", + 5, + 10, + medium_random_attachment_graph, + first_node_id, + |graph, source| { + let node = graph.node(source.clone()).expect("source node exists"); + in_component(node) + }, + ); +} + +pub fn graphgen_medium_in_component_filtered(c: &mut Criterion) { + graph_benchmark_with_setup( + c, + "graphgen_medium_in_component_filtered", + 5, + 10, + medium_random_attachment_graph, + first_node_id, + |graph, source| { + let node = graph.node(source.clone()).expect("source node exists"); + in_component_filtered(node, Unfiltered).unwrap() + }, + ); +} + +pub fn graphgen_internal_global_triangle_motifs(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_internal_global_triangle_motifs", + 10, + 10, + medium_random_attachment_graph, + |graph, _| global_triangle_motifs_internal(graph, vec![100], None), + ); +} + +pub fn graphgen_internal_local_triangle_motifs(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_internal_local_triangle_motifs", + 10, + 10, + medium_random_attachment_graph, + |graph, _| local_triangle_motifs_internal(graph, vec![100], None), + ); +} + +pub fn graphgen_medium_k_core_set(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_medium_k_core_set", + 5, + 10, + medium_random_attachment_graph, + |graph, _| k_core_set(graph, 2, usize::MAX, None), + ); +} + +pub fn graphgen_medium_k_core(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_medium_k_core", + 5, + 10, + medium_random_attachment_graph, + |graph, _| k_core(graph, 2, usize::MAX, None), + ); +} + +pub fn graphgen_medium_fast_rp(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_medium_fast_rp", + 10, + 10, + medium_random_attachment_graph, + |graph, _| fast_rp(graph, 32, 0.5, vec![1.0, 1.0, 1.0], Some(1), None), + ); +} + +pub fn graphgen_medium_temporal_bipartite_projection(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_medium_temporal_bipartite_projection", + 20, + 10, + medium_typed_random_attachment_graph, + |graph, _| temporal_bipartite_projection(graph, 1, "Right".to_string()), + ); +} + +pub fn temporal_motifs(c: &mut Criterion) { + graph_benchmark( + c, + "temporal_motifs", + 20, + 10, + medium_random_attachment_graph, + |graph, _| global_temporal_three_node_motif(graph, 100, None), + ); +} + +criterion_group!( + benches, + graphgen_medium_clustering_coeff, + graphgen_medium_pagerank, + graphgen_medium_hits, + graphgen_medium_triangle_count, + graphgen_medium_triplet_count, + graphgen_medium_reciprocity, + graphgen_medium_scc, + graphgen_medium_label_propagation, + graphgen_medium_louvain, + graphgen_medium_all_local_reciprocity, + graphgen_medium_balance, + graphgen_medium_temporal_motif_multi, + graphgen_medium_local_temporal_motif, + graphgen_medium_dijkstra, + graphgen_medium_single_source_shortest_path, + graphgen_medium_in_component, + graphgen_medium_in_component_filtered, + graphgen_internal_global_triangle_motifs, + graphgen_internal_local_triangle_motifs, + graphgen_medium_k_core_set, + graphgen_medium_k_core, + graphgen_medium_fast_rp, + graphgen_medium_temporal_bipartite_projection, + temporal_motifs, +); +criterion_main!(benches); diff --git a/raphtory-benchmark/benches/algobench_slow.rs b/raphtory-benchmark/benches/algobench_slow.rs new file mode 100644 index 0000000000..ccb72d2db9 --- /dev/null +++ b/raphtory-benchmark/benches/algobench_slow.rs @@ -0,0 +1,169 @@ +// Expensive algorithms (several hundred ms to multiple seconds per iteration on the +// 5000-node large graph). Run against the much smaller 100-node tiny graph instead, to keep +// total suite runtime reasonable - these algorithms are already the ones most likely to time +// out criterion's sampling window even at that reduced scale. +// +// `betweenness_centrality` is this binary's representative for graph/subgraph/layered/filtered +// view coverage; every other algorithm here only benchmarks the plain graph. + +use raphtory::{ + algorithms::{ + bipartite::max_weight_matching::max_weight_matching, + centrality::betweenness::betweenness_centrality, + components::{ + in_components, in_components_filtered, out_components, out_components_filtered, + }, + layout::{ + cohesive_fruchterman_reingold::cohesive_fruchterman_reingold, + fruchterman_reingold::fruchterman_reingold_unbounded, + }, + motifs::temporal_rich_club_coefficient::temporal_rich_club_coefficient, + }, + db::graph::views::filter::Unfiltered, + prelude::*, +}; +use criterion::{criterion_group, criterion_main, Criterion}; +use raphtory_benchmark::algobench_common::{ + graph_benchmark, tiny_random_attachment_filtered, tiny_random_attachment_graph, + tiny_random_attachment_layered, tiny_random_attachment_subgraph, +}; + +pub fn graphgen_large_betweenness(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_betweenness", + 20, + 10, + tiny_random_attachment_graph, + |graph, _| betweenness_centrality(graph, None, false), + ); + graph_benchmark( + c, + "graphgen_large_betweenness_subgraph", + 20, + 10, + tiny_random_attachment_subgraph, + |graph, _| betweenness_centrality(graph, None, false), + ); + graph_benchmark( + c, + "graphgen_large_betweenness_layered", + 20, + 10, + tiny_random_attachment_layered, + |graph, _| betweenness_centrality(graph, None, false), + ); + graph_benchmark( + c, + "graphgen_large_betweenness_graph_filtered", + 20, + 10, + tiny_random_attachment_filtered, + |graph, _| betweenness_centrality(graph, None, false), + ) +} + +pub fn graphgen_large_in_components(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_in_components", + 20, + 10, + tiny_random_attachment_graph, + |graph, _| in_components(graph, None), + ); +} + +pub fn graphgen_large_out_components(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_out_components", + 20, + 10, + tiny_random_attachment_graph, + |graph, _| out_components(graph, None), + ); +} + +pub fn graphgen_large_in_components_filtered(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_in_components_filtered", + 20, + 10, + tiny_random_attachment_graph, + |graph, _| in_components_filtered(graph, None, Unfiltered).unwrap(), + ); +} + +pub fn graphgen_large_out_components_filtered(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_out_components_filtered", + 20, + 10, + tiny_random_attachment_graph, + |graph, _| out_components_filtered(graph, None, Unfiltered).unwrap(), + ); +} + +pub fn graphgen_large_temporal_rich_club(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_temporal_rich_club", + 20, + 10, + tiny_random_attachment_graph, + |graph, _| { + let rolling = graph.rolling(1, Some(1)).unwrap(); + temporal_rich_club_coefficient(graph, rolling, 3, 3) + }, + ); +} + +pub fn graphgen_large_fruchterman_reingold(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_fruchterman_reingold", + 20, + 10, + tiny_random_attachment_graph, + |graph, _| fruchterman_reingold_unbounded(graph, 5, 1.0, 1.0, 0.9, 0.1), + ); +} + +pub fn graphgen_large_cohesive_fruchterman_reingold(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_cohesive_fruchterman_reingold", + 20, + 10, + tiny_random_attachment_graph, + |graph, _| cohesive_fruchterman_reingold(graph, 5, 1.0, 1.0, 0.9, 0.1), + ); +} + +pub fn graphgen_large_max_weight_matching(c: &mut Criterion) { + graph_benchmark( + c, + "graphgen_large_max_weight_matching", + 20, + 10, + tiny_random_attachment_graph, + |graph, _| max_weight_matching(graph, None, false, false), + ); +} + +criterion_group!( + benches, + graphgen_large_betweenness, + graphgen_large_in_components, + graphgen_large_out_components, + graphgen_large_in_components_filtered, + graphgen_large_out_components_filtered, + graphgen_large_temporal_rich_club, + graphgen_large_fruchterman_reingold, + graphgen_large_cohesive_fruchterman_reingold, + graphgen_large_max_weight_matching, +); +criterion_main!(benches); diff --git a/raphtory-benchmark/src/algobench_common.rs b/raphtory-benchmark/src/algobench_common.rs new file mode 100644 index 0000000000..fcb83b2838 --- /dev/null +++ b/raphtory-benchmark/src/algobench_common.rs @@ -0,0 +1,284 @@ +#![allow(dead_code)] + +// Shared infrastructure for the algobench_* benchmark binaries (see benches/algobench_*.rs). +// +// Benchmarks are split across binaries by algorithm speed/complexity (fast / medium / slow) +// so that a run of the fast or medium tier isn't held hostage by a handful of expensive +// algorithms, and so slow algorithms can run against a smaller graph to keep wall-clock time +// reasonable. Only `algobench_views` benchmarks the graph/subgraph/layered/filtered view +// variants (on a representative algorithm from each speed tier); every other binary only +// benchmarks the plain graph. +// +// The underlying random_attachment graphs are expensive to build, so each variant +// (plain / weighted / typed, large / tiny) is constructed once per process and cached; +// every benchmark reuses the cached graph (cheap `Arc` clone) and only builds a cheap view +// (subgraph/filter/layer) on top of it. + +use criterion::{Criterion, SamplingMode}; +use raphtory::{ + db::{ + api::view::{Filter, StaticGraphViewOps}, + graph::views::{ + filter::model::{ + degree_filter::DegreeFilterFactory, property_filter::ops::PropertyFilterOps, + }, + node_subgraph::NodeSubgraph, + }, + }, + graphgen::random_attachment::random_attachment, + prelude::*, +}; +use std::{hint::black_box, sync::OnceLock}; + +pub fn graph_benchmark_with_setup( + c: &mut Criterion, + name: &str, + measurement_secs: u64, + sample_size: usize, + build_graph: BuildGraph, + setup: Setup, + mut run: Run, +) where + G: StaticGraphViewOps, + BuildGraph: FnOnce() -> G, + Setup: Fn(&G) -> SetupData, + Run: FnMut(&G, &SetupData) -> Output, +{ + let mut group = c.benchmark_group(name); + let graph = build_graph(); + let setup_data = setup(&graph); + + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(measurement_secs)); + group.sample_size(sample_size); + group.bench_function(name, |b| { + b.iter(|| { + let result = run(&graph, &setup_data); + black_box(result); + }); + }); + group.finish() +} + +pub fn graph_benchmark( + c: &mut Criterion, + name: &str, + measurement_secs: u64, + sample_size: usize, + build_graph: BuildGraph, + run: Run, +) where + G: StaticGraphViewOps, + BuildGraph: FnOnce() -> G, + Run: FnMut(&G, &()) -> Output, +{ + graph_benchmark_with_setup( + c, + name, + measurement_secs, + sample_size, + build_graph, + |_| (), + run, + ) +} + +pub fn simple_benchmark( + c: &mut Criterion, + name: &str, + measurement_secs: u64, + sample_size: usize, + mut run: Run, +) where + Run: FnMut() -> Output, +{ + let mut group = c.benchmark_group(name); + group.sampling_mode(SamplingMode::Flat); + group.measurement_time(std::time::Duration::from_secs(measurement_secs)); + group.sample_size(sample_size); + group.bench_function(name, |b| { + b.iter(|| { + let result = run(); + black_box(result); + }); + }); + group.finish() +} + +pub fn first_node_id(graph: &G) -> GID { + graph + .nodes() + .id() + .iter_values() + .next() + .expect("graph has nodes") +} + +// Large graph (5000 nodes) - used by the fast/medium tiers and as the base for the +// representative fast/medium/trivial algorithms in algobench_views. + +pub fn build_large_random_attachment_graph() -> Graph { + let graph = Graph::new(); + let seed: [u8; 32] = [1; 32]; + random_attachment(&graph, 5000, 4, Some(seed)); + graph +} + +pub fn large_random_attachment_graph() -> Graph { + static GRAPH: OnceLock = OnceLock::new(); + GRAPH.get_or_init(build_large_random_attachment_graph).clone() +} + +pub fn large_random_attachment_subgraph() -> NodeSubgraph { + let graph = large_random_attachment_graph(); + let subgraph = graph.subgraph(graph.nodes()); + subgraph +} + +pub fn large_random_attachment_filtered() -> impl StaticGraphViewOps { + large_random_attachment_graph() + .filter(NodeFilter.degree().ge(0u64)) + .unwrap() +} + +pub fn large_random_attachment_layered() -> impl StaticGraphViewOps { + let graph = large_random_attachment_graph(); + graph.default_layer() +} + +pub fn build_large_weighted_random_attachment_graph() -> Graph { + let graph = build_large_random_attachment_graph(); + let ids = graph.nodes().id().iter_values().collect::>(); + if let (Some(src), Some(dst)) = (ids.first(), ids.get(1)) { + graph + .add_edge(0, src.clone(), dst.clone(), [("weight", 1.0f64)], None) + .expect("unable to add weighted edge"); + } + graph +} + +pub fn large_weighted_random_attachment_graph() -> Graph { + static GRAPH: OnceLock = OnceLock::new(); + GRAPH + .get_or_init(build_large_weighted_random_attachment_graph) + .clone() +} + +pub fn build_large_typed_random_attachment_graph() -> Graph { + let graph = build_large_random_attachment_graph(); + for id in graph.nodes().id().iter_values() { + graph + .add_node(0, id, NO_PROPS, Some("Right"), None) + .expect("unable to set node type"); + } + graph +} + +pub fn large_typed_random_attachment_graph() -> Graph { + static GRAPH: OnceLock = OnceLock::new(); + GRAPH + .get_or_init(build_large_typed_random_attachment_graph) + .clone() +} + +// Medium graph (1500 nodes) - dedicated to algobench_medium, distinct from the large +// (5000 node) graph so that binary isn't just running the fast/slow tiers' graph at a +// different set of algorithms. + +pub fn build_medium_random_attachment_graph() -> Graph { + let graph = Graph::new(); + let seed: [u8; 32] = [1; 32]; + random_attachment(&graph, 1500, 4, Some(seed)); + graph +} + +pub fn medium_random_attachment_graph() -> Graph { + static GRAPH: OnceLock = OnceLock::new(); + GRAPH + .get_or_init(build_medium_random_attachment_graph) + .clone() +} + +pub fn medium_random_attachment_subgraph() -> NodeSubgraph { + let graph = medium_random_attachment_graph(); + let subgraph = graph.subgraph(graph.nodes()); + subgraph +} + +pub fn medium_random_attachment_filtered() -> impl StaticGraphViewOps { + medium_random_attachment_graph() + .filter(NodeFilter.degree().ge(0u64)) + .unwrap() +} + +pub fn medium_random_attachment_layered() -> impl StaticGraphViewOps { + let graph = medium_random_attachment_graph(); + graph.default_layer() +} + +pub fn build_medium_weighted_random_attachment_graph() -> Graph { + let graph = build_medium_random_attachment_graph(); + let ids = graph.nodes().id().iter_values().collect::>(); + if let (Some(src), Some(dst)) = (ids.first(), ids.get(1)) { + graph + .add_edge(0, src.clone(), dst.clone(), [("weight", 1.0f64)], None) + .expect("unable to add weighted edge"); + } + graph +} + +pub fn medium_weighted_random_attachment_graph() -> Graph { + static GRAPH: OnceLock = OnceLock::new(); + GRAPH + .get_or_init(build_medium_weighted_random_attachment_graph) + .clone() +} + +pub fn build_medium_typed_random_attachment_graph() -> Graph { + let graph = build_medium_random_attachment_graph(); + for id in graph.nodes().id().iter_values() { + graph + .add_node(0, id, NO_PROPS, Some("Right"), None) + .expect("unable to set node type"); + } + graph +} + +pub fn medium_typed_random_attachment_graph() -> Graph { + static GRAPH: OnceLock = OnceLock::new(); + GRAPH + .get_or_init(build_medium_typed_random_attachment_graph) + .clone() +} + +// Tiny graph (100 nodes) - dedicated to algorithms too expensive to run at the large +// graph's 5000-node scale (components, betweenness, temporal rich club, matching, layout). + +pub fn build_tiny_random_attachment_graph() -> Graph { + let graph = Graph::new(); + let seed: [u8; 32] = [1; 32]; + random_attachment(&graph, 100, 4, Some(seed)); + graph +} + +pub fn tiny_random_attachment_graph() -> Graph { + static GRAPH: OnceLock = OnceLock::new(); + GRAPH.get_or_init(build_tiny_random_attachment_graph).clone() +} + +pub fn tiny_random_attachment_subgraph() -> NodeSubgraph { + let graph = tiny_random_attachment_graph(); + let subgraph = graph.subgraph(graph.nodes()); + subgraph +} + +pub fn tiny_random_attachment_filtered() -> impl StaticGraphViewOps { + tiny_random_attachment_graph() + .filter(NodeFilter.degree().ge(0u64)) + .unwrap() +} + +pub fn tiny_random_attachment_layered() -> impl StaticGraphViewOps { + let graph = tiny_random_attachment_graph(); + graph.default_layer() +} diff --git a/raphtory-benchmark/src/lib.rs b/raphtory-benchmark/src/lib.rs index 14d1c1908e..269055d068 100644 --- a/raphtory-benchmark/src/lib.rs +++ b/raphtory-benchmark/src/lib.rs @@ -1,2 +1,3 @@ +pub mod algobench_common; pub mod common; pub mod graph_gen; From a4383e59a4dc9a126319f9f825c01724deb0a78a Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Mon, 3 Aug 2026 17:06:42 -0500 Subject: [PATCH 17/24] mdify benchmark yml --- .github/workflows/benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index feffb49f24..2ea0bf9890 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -41,7 +41,7 @@ jobs: - name: Run benchmark (Unix) run: | set -o pipefail - cargo bench --bench base --bench algobench -p raphtory-benchmark -- --output-format=bencher | tee benchmark-result.txt + cargo bench --bench base --bench algobench_fast --bench algobench_medium --bench algobench_slow -p raphtory-benchmark -- --output-format=bencher | tee benchmark-result.txt - name: Restore Cargo.lock to avoid dirty working tree run: git checkout -- Cargo.lock - name: Store benchmark results from master branch From 1ed6792a69e131e49170a6a3bac00c0282f3b05c Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Mon, 3 Aug 2026 18:12:17 -0500 Subject: [PATCH 18/24] got rid of confusing prefixes --- raphtory-benchmark/benches/algobench_fast.rs | 102 +++++++------- .../benches/algobench_medium.rs | 132 +++++++++--------- raphtory-benchmark/benches/algobench_slow.rs | 60 ++++---- 3 files changed, 147 insertions(+), 147 deletions(-) diff --git a/raphtory-benchmark/benches/algobench_fast.rs b/raphtory-benchmark/benches/algobench_fast.rs index 1e2e4aecc8..554b869f56 100644 --- a/raphtory-benchmark/benches/algobench_fast.rs +++ b/raphtory-benchmark/benches/algobench_fast.rs @@ -65,10 +65,10 @@ pub fn local_clustering_coefficient_analysis(c: &mut Criterion) { ); } -pub fn graphgen_large_directed_density(c: &mut Criterion) { +pub fn graphgen_directed_density(c: &mut Criterion) { graph_benchmark( c, - "graphgen_large_directed_density", + "graphgen_directed_density", 2, 10, large_random_attachment_graph, @@ -76,7 +76,7 @@ pub fn graphgen_large_directed_density(c: &mut Criterion) { ); graph_benchmark( c, - "graphgen_large_directed_density_subgraph", + "graphgen_directed_density_subgraph", 3, 10, large_random_attachment_subgraph, @@ -84,7 +84,7 @@ pub fn graphgen_large_directed_density(c: &mut Criterion) { ); graph_benchmark( c, - "graphgen_large_directed_density_layered", + "graphgen_directed_density_layered", 3, 10, large_random_attachment_layered, @@ -92,7 +92,7 @@ pub fn graphgen_large_directed_density(c: &mut Criterion) { ); graph_benchmark( c, - "graphgen_large_directed_density_graph_filtered", + "graphgen_directed_density_graph_filtered", 5, 10, large_random_attachment_filtered, @@ -100,10 +100,10 @@ pub fn graphgen_large_directed_density(c: &mut Criterion) { ) } -pub fn graphgen_large_degree_centrality(c: &mut Criterion) { +pub fn graphgen_degree_centrality(c: &mut Criterion) { graph_benchmark( c, - "graphgen_large_degree_centrality", + "graphgen_degree_centrality", 3, 10, large_random_attachment_graph, @@ -111,10 +111,10 @@ pub fn graphgen_large_degree_centrality(c: &mut Criterion) { ); } -pub fn graphgen_large_concomp(c: &mut Criterion) { +pub fn graphgen_concomp(c: &mut Criterion) { graph_benchmark( c, - "graphgen_large_concomp", + "graphgen_concomp", 5, 10, large_random_attachment_graph, @@ -122,10 +122,10 @@ pub fn graphgen_large_concomp(c: &mut Criterion) { ); } -pub fn graphgen_large_alternating_mask(c: &mut Criterion) { +pub fn graphgen_alternating_mask(c: &mut Criterion) { graph_benchmark( c, - "graphgen_large_alternating_mask", + "graphgen_alternating_mask", 3, 10, large_random_attachment_graph, @@ -133,10 +133,10 @@ pub fn graphgen_large_alternating_mask(c: &mut Criterion) { ); } -pub fn graphgen_large_max_degree(c: &mut Criterion) { +pub fn graphgen_max_degree(c: &mut Criterion) { graph_benchmark( c, - "graphgen_large_max_degree", + "graphgen_max_degree", 3, 10, large_random_attachment_graph, @@ -144,10 +144,10 @@ pub fn graphgen_large_max_degree(c: &mut Criterion) { ); } -pub fn graphgen_large_min_degree(c: &mut Criterion) { +pub fn graphgen_min_degree(c: &mut Criterion) { graph_benchmark( c, - "graphgen_large_min_degree", + "graphgen_min_degree", 3, 10, large_random_attachment_graph, @@ -155,10 +155,10 @@ pub fn graphgen_large_min_degree(c: &mut Criterion) { ); } -pub fn graphgen_large_max_out_degree(c: &mut Criterion) { +pub fn graphgen_max_out_degree(c: &mut Criterion) { graph_benchmark( c, - "graphgen_large_max_out_degree", + "graphgen_max_out_degree", 3, 10, large_random_attachment_graph, @@ -166,10 +166,10 @@ pub fn graphgen_large_max_out_degree(c: &mut Criterion) { ); } -pub fn graphgen_large_max_in_degree(c: &mut Criterion) { +pub fn graphgen_max_in_degree(c: &mut Criterion) { graph_benchmark( c, - "graphgen_large_max_in_degree", + "graphgen_max_in_degree", 3, 10, large_random_attachment_graph, @@ -177,10 +177,10 @@ pub fn graphgen_large_max_in_degree(c: &mut Criterion) { ); } -pub fn graphgen_large_min_out_degree(c: &mut Criterion) { +pub fn graphgen_min_out_degree(c: &mut Criterion) { graph_benchmark( c, - "graphgen_large_min_out_degree", + "graphgen_min_out_degree", 3, 10, large_random_attachment_graph, @@ -188,10 +188,10 @@ pub fn graphgen_large_min_out_degree(c: &mut Criterion) { ); } -pub fn graphgen_large_min_in_degree(c: &mut Criterion) { +pub fn graphgen_min_in_degree(c: &mut Criterion) { graph_benchmark( c, - "graphgen_large_min_in_degree", + "graphgen_min_in_degree", 3, 10, large_random_attachment_graph, @@ -199,10 +199,10 @@ pub fn graphgen_large_min_in_degree(c: &mut Criterion) { ); } -pub fn graphgen_large_average_degree(c: &mut Criterion) { +pub fn graphgen_average_degree(c: &mut Criterion) { graph_benchmark( c, - "graphgen_large_average_degree", + "graphgen_average_degree", 3, 10, large_random_attachment_graph, @@ -210,10 +210,10 @@ pub fn graphgen_large_average_degree(c: &mut Criterion) { ); } -pub fn graphgen_large_local_clustering_coefficient_batch(c: &mut Criterion) { +pub fn graphgen_local_clustering_coefficient_batch(c: &mut Criterion) { graph_benchmark_with_setup( c, - "graphgen_large_local_clustering_coefficient_batch", + "graphgen_local_clustering_coefficient_batch", 3, 10, large_random_attachment_graph, @@ -222,10 +222,10 @@ pub fn graphgen_large_local_clustering_coefficient_batch(c: &mut Criterion) { ); } -pub fn graphgen_large_temporally_reachable_nodes(c: &mut Criterion) { +pub fn graphgen_temporally_reachable_nodes(c: &mut Criterion) { graph_benchmark_with_setup( c, - "graphgen_large_temporally_reachable_nodes", + "graphgen_temporally_reachable_nodes", 3, 10, large_random_attachment_graph, @@ -234,10 +234,10 @@ pub fn graphgen_large_temporally_reachable_nodes(c: &mut Criterion) { ); } -pub fn graphgen_large_out_component(c: &mut Criterion) { +pub fn graphgen_out_component(c: &mut Criterion) { graph_benchmark_with_setup( c, - "graphgen_large_out_component", + "graphgen_out_component", 3, 10, large_random_attachment_graph, @@ -249,10 +249,10 @@ pub fn graphgen_large_out_component(c: &mut Criterion) { ); } -pub fn graphgen_large_out_component_filtered(c: &mut Criterion) { +pub fn graphgen_out_component_filtered(c: &mut Criterion) { graph_benchmark_with_setup( c, - "graphgen_large_out_component_filtered", + "graphgen_out_component_filtered", 3, 10, large_random_attachment_graph, @@ -264,10 +264,10 @@ pub fn graphgen_large_out_component_filtered(c: &mut Criterion) { ); } -pub fn graphgen_large_temporal_seir(c: &mut Criterion) { +pub fn graphgen_temporal_seir(c: &mut Criterion) { graph_benchmark( c, - "graphgen_large_temporal_seir", + "graphgen_temporal_seir", 3, 10, large_random_attachment_graph, @@ -318,22 +318,22 @@ criterion_group!( benches, local_triangle_count_analysis, local_clustering_coefficient_analysis, - graphgen_large_directed_density, - graphgen_large_degree_centrality, - graphgen_large_concomp, - graphgen_large_alternating_mask, - graphgen_large_max_degree, - graphgen_large_min_degree, - graphgen_large_max_out_degree, - graphgen_large_max_in_degree, - graphgen_large_min_out_degree, - graphgen_large_min_in_degree, - graphgen_large_average_degree, - graphgen_large_local_clustering_coefficient_batch, - graphgen_large_temporally_reachable_nodes, - graphgen_large_out_component, - graphgen_large_out_component_filtered, - graphgen_large_temporal_seir, + graphgen_directed_density, + graphgen_degree_centrality, + graphgen_concomp, + graphgen_alternating_mask, + graphgen_max_degree, + graphgen_min_degree, + graphgen_max_out_degree, + graphgen_max_in_degree, + graphgen_min_out_degree, + graphgen_min_in_degree, + graphgen_average_degree, + graphgen_local_clustering_coefficient_batch, + graphgen_temporally_reachable_nodes, + graphgen_out_component, + graphgen_out_component_filtered, + graphgen_temporal_seir, graphgen_internal_two_node_event, graphgen_internal_init_two_node_count, graphgen_internal_star_event, diff --git a/raphtory-benchmark/benches/algobench_medium.rs b/raphtory-benchmark/benches/algobench_medium.rs index f036c0403a..3e3d32fbf9 100644 --- a/raphtory-benchmark/benches/algobench_medium.rs +++ b/raphtory-benchmark/benches/algobench_medium.rs @@ -49,10 +49,10 @@ use raphtory_benchmark::algobench_common::{ medium_weighted_random_attachment_graph, }; -pub fn graphgen_medium_clustering_coeff(c: &mut Criterion) { +pub fn graphgen_clustering_coeff(c: &mut Criterion) { graph_benchmark( c, - "graphgen_medium_clustering_coeff", + "graphgen_clustering_coeff", 10, 10, medium_random_attachment_graph, @@ -60,10 +60,10 @@ pub fn graphgen_medium_clustering_coeff(c: &mut Criterion) { ); } -pub fn graphgen_medium_pagerank(c: &mut Criterion) { +pub fn graphgen_pagerank(c: &mut Criterion) { graph_benchmark( c, - "graphgen_medium_pagerank", + "graphgen_pagerank", 10, 10, medium_random_attachment_graph, @@ -71,7 +71,7 @@ pub fn graphgen_medium_pagerank(c: &mut Criterion) { ); graph_benchmark( c, - "graphgen_medium_pagerank_subgraph", + "graphgen_pagerank_subgraph", 10, 10, medium_random_attachment_subgraph, @@ -79,7 +79,7 @@ pub fn graphgen_medium_pagerank(c: &mut Criterion) { ); graph_benchmark( c, - "graphgen_medium_pagerank_layered", + "graphgen_pagerank_layered", 10, 10, medium_random_attachment_layered, @@ -87,7 +87,7 @@ pub fn graphgen_medium_pagerank(c: &mut Criterion) { ); graph_benchmark( c, - "graphgen_medium_pagerank_graph_filtered", + "graphgen_pagerank_graph_filtered", 20, 10, medium_random_attachment_filtered, @@ -95,10 +95,10 @@ pub fn graphgen_medium_pagerank(c: &mut Criterion) { ) } -pub fn graphgen_medium_hits(c: &mut Criterion) { +pub fn graphgen_hits(c: &mut Criterion) { graph_benchmark( c, - "graphgen_medium_hits", + "graphgen_hits", 5, 10, medium_random_attachment_graph, @@ -106,10 +106,10 @@ pub fn graphgen_medium_hits(c: &mut Criterion) { ); } -pub fn graphgen_medium_triangle_count(c: &mut Criterion) { +pub fn graphgen_triangle_count(c: &mut Criterion) { graph_benchmark( c, - "graphgen_medium_triangle_count", + "graphgen_triangle_count", 10, 10, medium_random_attachment_graph, @@ -117,10 +117,10 @@ pub fn graphgen_medium_triangle_count(c: &mut Criterion) { ); } -pub fn graphgen_medium_triplet_count(c: &mut Criterion) { +pub fn graphgen_triplet_count(c: &mut Criterion) { graph_benchmark( c, - "graphgen_medium_triplet_count", + "graphgen_triplet_count", 5, 10, medium_random_attachment_graph, @@ -128,10 +128,10 @@ pub fn graphgen_medium_triplet_count(c: &mut Criterion) { ); } -pub fn graphgen_medium_reciprocity(c: &mut Criterion) { +pub fn graphgen_reciprocity(c: &mut Criterion) { graph_benchmark( c, - "graphgen_medium_reciprocity", + "graphgen_reciprocity", 5, 10, medium_random_attachment_graph, @@ -139,10 +139,10 @@ pub fn graphgen_medium_reciprocity(c: &mut Criterion) { ); } -pub fn graphgen_medium_scc(c: &mut Criterion) { +pub fn graphgen_scc(c: &mut Criterion) { graph_benchmark( c, - "graphgen_medium_scc", + "graphgen_scc", 5, 10, medium_random_attachment_graph, @@ -150,10 +150,10 @@ pub fn graphgen_medium_scc(c: &mut Criterion) { ); } -pub fn graphgen_medium_label_propagation(c: &mut Criterion) { +pub fn graphgen_label_propagation(c: &mut Criterion) { graph_benchmark( c, - "graphgen_medium_label_propagation", + "graphgen_label_propagation", 20, 10, medium_random_attachment_graph, @@ -161,10 +161,10 @@ pub fn graphgen_medium_label_propagation(c: &mut Criterion) { ); } -pub fn graphgen_medium_louvain(c: &mut Criterion) { +pub fn graphgen_louvain(c: &mut Criterion) { graph_benchmark( c, - "graphgen_medium_louvain", + "graphgen_louvain", 20, 10, medium_random_attachment_graph, @@ -172,10 +172,10 @@ pub fn graphgen_medium_louvain(c: &mut Criterion) { ); } -pub fn graphgen_medium_all_local_reciprocity(c: &mut Criterion) { +pub fn graphgen_all_local_reciprocity(c: &mut Criterion) { graph_benchmark( c, - "graphgen_medium_all_local_reciprocity", + "graphgen_all_local_reciprocity", 5, 10, medium_random_attachment_graph, @@ -183,10 +183,10 @@ pub fn graphgen_medium_all_local_reciprocity(c: &mut Criterion) { ); } -pub fn graphgen_medium_balance(c: &mut Criterion) { +pub fn graphgen_balance(c: &mut Criterion) { graph_benchmark( c, - "graphgen_medium_balance", + "graphgen_balance", 5, 10, medium_weighted_random_attachment_graph, @@ -194,10 +194,10 @@ pub fn graphgen_medium_balance(c: &mut Criterion) { ); } -pub fn graphgen_medium_temporal_motif_multi(c: &mut Criterion) { +pub fn graphgen_temporal_motif_multi(c: &mut Criterion) { graph_benchmark( c, - "graphgen_medium_temporal_motif_multi", + "graphgen_temporal_motif_multi", 20, 10, medium_random_attachment_graph, @@ -205,10 +205,10 @@ pub fn graphgen_medium_temporal_motif_multi(c: &mut Criterion) { ); } -pub fn graphgen_medium_local_temporal_motif(c: &mut Criterion) { +pub fn graphgen_local_temporal_motif(c: &mut Criterion) { graph_benchmark( c, - "graphgen_medium_local_temporal_motif", + "graphgen_local_temporal_motif", 20, 10, medium_random_attachment_graph, @@ -216,10 +216,10 @@ pub fn graphgen_medium_local_temporal_motif(c: &mut Criterion) { ); } -pub fn graphgen_medium_dijkstra(c: &mut Criterion) { +pub fn graphgen_dijkstra(c: &mut Criterion) { graph_benchmark_with_setup( c, - "graphgen_medium_dijkstra", + "graphgen_dijkstra", 5, 10, medium_random_attachment_graph, @@ -237,10 +237,10 @@ pub fn graphgen_medium_dijkstra(c: &mut Criterion) { ); } -pub fn graphgen_medium_single_source_shortest_path(c: &mut Criterion) { +pub fn graphgen_single_source_shortest_path(c: &mut Criterion) { graph_benchmark_with_setup( c, - "graphgen_medium_single_source_shortest_path", + "graphgen_single_source_shortest_path", 5, 10, medium_random_attachment_graph, @@ -249,10 +249,10 @@ pub fn graphgen_medium_single_source_shortest_path(c: &mut Criterion) { ); } -pub fn graphgen_medium_in_component(c: &mut Criterion) { +pub fn graphgen_in_component(c: &mut Criterion) { graph_benchmark_with_setup( c, - "graphgen_medium_in_component", + "graphgen_in_component", 5, 10, medium_random_attachment_graph, @@ -264,10 +264,10 @@ pub fn graphgen_medium_in_component(c: &mut Criterion) { ); } -pub fn graphgen_medium_in_component_filtered(c: &mut Criterion) { +pub fn graphgen_in_component_filtered(c: &mut Criterion) { graph_benchmark_with_setup( c, - "graphgen_medium_in_component_filtered", + "graphgen_in_component_filtered", 5, 10, medium_random_attachment_graph, @@ -301,10 +301,10 @@ pub fn graphgen_internal_local_triangle_motifs(c: &mut Criterion) { ); } -pub fn graphgen_medium_k_core_set(c: &mut Criterion) { +pub fn graphgen_k_core_set(c: &mut Criterion) { graph_benchmark( c, - "graphgen_medium_k_core_set", + "graphgen_k_core_set", 5, 10, medium_random_attachment_graph, @@ -312,10 +312,10 @@ pub fn graphgen_medium_k_core_set(c: &mut Criterion) { ); } -pub fn graphgen_medium_k_core(c: &mut Criterion) { +pub fn graphgen_k_core(c: &mut Criterion) { graph_benchmark( c, - "graphgen_medium_k_core", + "graphgen_k_core", 5, 10, medium_random_attachment_graph, @@ -323,10 +323,10 @@ pub fn graphgen_medium_k_core(c: &mut Criterion) { ); } -pub fn graphgen_medium_fast_rp(c: &mut Criterion) { +pub fn graphgen_fast_rp(c: &mut Criterion) { graph_benchmark( c, - "graphgen_medium_fast_rp", + "graphgen_fast_rp", 10, 10, medium_random_attachment_graph, @@ -334,10 +334,10 @@ pub fn graphgen_medium_fast_rp(c: &mut Criterion) { ); } -pub fn graphgen_medium_temporal_bipartite_projection(c: &mut Criterion) { +pub fn graphgen_temporal_bipartite_projection(c: &mut Criterion) { graph_benchmark( c, - "graphgen_medium_temporal_bipartite_projection", + "graphgen_temporal_bipartite_projection", 20, 10, medium_typed_random_attachment_graph, @@ -358,29 +358,29 @@ pub fn temporal_motifs(c: &mut Criterion) { criterion_group!( benches, - graphgen_medium_clustering_coeff, - graphgen_medium_pagerank, - graphgen_medium_hits, - graphgen_medium_triangle_count, - graphgen_medium_triplet_count, - graphgen_medium_reciprocity, - graphgen_medium_scc, - graphgen_medium_label_propagation, - graphgen_medium_louvain, - graphgen_medium_all_local_reciprocity, - graphgen_medium_balance, - graphgen_medium_temporal_motif_multi, - graphgen_medium_local_temporal_motif, - graphgen_medium_dijkstra, - graphgen_medium_single_source_shortest_path, - graphgen_medium_in_component, - graphgen_medium_in_component_filtered, + graphgen_clustering_coeff, + graphgen_pagerank, + graphgen_hits, + graphgen_triangle_count, + graphgen_triplet_count, + graphgen_reciprocity, + graphgen_scc, + graphgen_label_propagation, + graphgen_louvain, + graphgen_all_local_reciprocity, + graphgen_balance, + graphgen_temporal_motif_multi, + graphgen_local_temporal_motif, + graphgen_dijkstra, + graphgen_single_source_shortest_path, + graphgen_in_component, + graphgen_in_component_filtered, graphgen_internal_global_triangle_motifs, graphgen_internal_local_triangle_motifs, - graphgen_medium_k_core_set, - graphgen_medium_k_core, - graphgen_medium_fast_rp, - graphgen_medium_temporal_bipartite_projection, + graphgen_k_core_set, + graphgen_k_core, + graphgen_fast_rp, + graphgen_temporal_bipartite_projection, temporal_motifs, ); criterion_main!(benches); diff --git a/raphtory-benchmark/benches/algobench_slow.rs b/raphtory-benchmark/benches/algobench_slow.rs index ccb72d2db9..959e2c6222 100644 --- a/raphtory-benchmark/benches/algobench_slow.rs +++ b/raphtory-benchmark/benches/algobench_slow.rs @@ -28,10 +28,10 @@ use raphtory_benchmark::algobench_common::{ tiny_random_attachment_layered, tiny_random_attachment_subgraph, }; -pub fn graphgen_large_betweenness(c: &mut Criterion) { +pub fn graphgen_betweenness(c: &mut Criterion) { graph_benchmark( c, - "graphgen_large_betweenness", + "graphgen_betweenness", 20, 10, tiny_random_attachment_graph, @@ -39,7 +39,7 @@ pub fn graphgen_large_betweenness(c: &mut Criterion) { ); graph_benchmark( c, - "graphgen_large_betweenness_subgraph", + "graphgen_betweenness_subgraph", 20, 10, tiny_random_attachment_subgraph, @@ -47,7 +47,7 @@ pub fn graphgen_large_betweenness(c: &mut Criterion) { ); graph_benchmark( c, - "graphgen_large_betweenness_layered", + "graphgen_betweenness_layered", 20, 10, tiny_random_attachment_layered, @@ -55,7 +55,7 @@ pub fn graphgen_large_betweenness(c: &mut Criterion) { ); graph_benchmark( c, - "graphgen_large_betweenness_graph_filtered", + "graphgen_betweenness_graph_filtered", 20, 10, tiny_random_attachment_filtered, @@ -63,10 +63,10 @@ pub fn graphgen_large_betweenness(c: &mut Criterion) { ) } -pub fn graphgen_large_in_components(c: &mut Criterion) { +pub fn graphgen_in_components(c: &mut Criterion) { graph_benchmark( c, - "graphgen_large_in_components", + "graphgen_in_components", 20, 10, tiny_random_attachment_graph, @@ -74,10 +74,10 @@ pub fn graphgen_large_in_components(c: &mut Criterion) { ); } -pub fn graphgen_large_out_components(c: &mut Criterion) { +pub fn graphgen_out_components(c: &mut Criterion) { graph_benchmark( c, - "graphgen_large_out_components", + "graphgen_out_components", 20, 10, tiny_random_attachment_graph, @@ -85,10 +85,10 @@ pub fn graphgen_large_out_components(c: &mut Criterion) { ); } -pub fn graphgen_large_in_components_filtered(c: &mut Criterion) { +pub fn graphgen_in_components_filtered(c: &mut Criterion) { graph_benchmark( c, - "graphgen_large_in_components_filtered", + "graphgen_in_components_filtered", 20, 10, tiny_random_attachment_graph, @@ -96,10 +96,10 @@ pub fn graphgen_large_in_components_filtered(c: &mut Criterion) { ); } -pub fn graphgen_large_out_components_filtered(c: &mut Criterion) { +pub fn graphgen_out_components_filtered(c: &mut Criterion) { graph_benchmark( c, - "graphgen_large_out_components_filtered", + "graphgen_out_components_filtered", 20, 10, tiny_random_attachment_graph, @@ -107,10 +107,10 @@ pub fn graphgen_large_out_components_filtered(c: &mut Criterion) { ); } -pub fn graphgen_large_temporal_rich_club(c: &mut Criterion) { +pub fn graphgen_temporal_rich_club(c: &mut Criterion) { graph_benchmark( c, - "graphgen_large_temporal_rich_club", + "graphgen_temporal_rich_club", 20, 10, tiny_random_attachment_graph, @@ -121,10 +121,10 @@ pub fn graphgen_large_temporal_rich_club(c: &mut Criterion) { ); } -pub fn graphgen_large_fruchterman_reingold(c: &mut Criterion) { +pub fn graphgen_fruchterman_reingold(c: &mut Criterion) { graph_benchmark( c, - "graphgen_large_fruchterman_reingold", + "graphgen_fruchterman_reingold", 20, 10, tiny_random_attachment_graph, @@ -132,10 +132,10 @@ pub fn graphgen_large_fruchterman_reingold(c: &mut Criterion) { ); } -pub fn graphgen_large_cohesive_fruchterman_reingold(c: &mut Criterion) { +pub fn graphgen_cohesive_fruchterman_reingold(c: &mut Criterion) { graph_benchmark( c, - "graphgen_large_cohesive_fruchterman_reingold", + "graphgen_cohesive_fruchterman_reingold", 20, 10, tiny_random_attachment_graph, @@ -143,10 +143,10 @@ pub fn graphgen_large_cohesive_fruchterman_reingold(c: &mut Criterion) { ); } -pub fn graphgen_large_max_weight_matching(c: &mut Criterion) { +pub fn graphgen_max_weight_matching(c: &mut Criterion) { graph_benchmark( c, - "graphgen_large_max_weight_matching", + "graphgen_max_weight_matching", 20, 10, tiny_random_attachment_graph, @@ -156,14 +156,14 @@ pub fn graphgen_large_max_weight_matching(c: &mut Criterion) { criterion_group!( benches, - graphgen_large_betweenness, - graphgen_large_in_components, - graphgen_large_out_components, - graphgen_large_in_components_filtered, - graphgen_large_out_components_filtered, - graphgen_large_temporal_rich_club, - graphgen_large_fruchterman_reingold, - graphgen_large_cohesive_fruchterman_reingold, - graphgen_large_max_weight_matching, + graphgen_betweenness, + graphgen_in_components, + graphgen_out_components, + graphgen_in_components_filtered, + graphgen_out_components_filtered, + graphgen_temporal_rich_club, + graphgen_fruchterman_reingold, + graphgen_cohesive_fruchterman_reingold, + graphgen_max_weight_matching, ); criterion_main!(benches); From 292972e3989ffbd54da0a1188c1d82c63b97d574 Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Tue, 4 Aug 2026 12:19:47 -0500 Subject: [PATCH 19/24] wip --- raphtory-benchmark/benches/algobench_fast.rs | 33 +++--------- .../benches/algobench_medium.rs | 27 ---------- raphtory-benchmark/benches/algobench_slow.rs | 16 +----- raphtory-benchmark/src/algobench_common.rs | 54 +++++++++++-------- 4 files changed, 39 insertions(+), 91 deletions(-) diff --git a/raphtory-benchmark/benches/algobench_fast.rs b/raphtory-benchmark/benches/algobench_fast.rs index 554b869f56..5126c3b6ac 100644 --- a/raphtory-benchmark/benches/algobench_fast.rs +++ b/raphtory-benchmark/benches/algobench_fast.rs @@ -45,7 +45,6 @@ pub fn local_triangle_count_analysis(c: &mut Criterion) { graph_benchmark_with_setup( c, "local_triangle_count", - 3, 10, large_random_attachment_graph, first_node_id, @@ -57,7 +56,6 @@ pub fn local_clustering_coefficient_analysis(c: &mut Criterion) { graph_benchmark_with_setup( c, "local_clustering_coefficient", - 3, 10, large_random_attachment_graph, first_node_id, @@ -69,7 +67,6 @@ pub fn graphgen_directed_density(c: &mut Criterion) { graph_benchmark( c, "graphgen_directed_density", - 2, 10, large_random_attachment_graph, |graph, _| directed_graph_density(graph), @@ -77,7 +74,6 @@ pub fn graphgen_directed_density(c: &mut Criterion) { graph_benchmark( c, "graphgen_directed_density_subgraph", - 3, 10, large_random_attachment_subgraph, |graph, _| directed_graph_density(graph), @@ -85,7 +81,6 @@ pub fn graphgen_directed_density(c: &mut Criterion) { graph_benchmark( c, "graphgen_directed_density_layered", - 3, 10, large_random_attachment_layered, |graph, _| directed_graph_density(graph), @@ -93,7 +88,6 @@ pub fn graphgen_directed_density(c: &mut Criterion) { graph_benchmark( c, "graphgen_directed_density_graph_filtered", - 5, 10, large_random_attachment_filtered, |graph, _| directed_graph_density(graph), @@ -104,7 +98,6 @@ pub fn graphgen_degree_centrality(c: &mut Criterion) { graph_benchmark( c, "graphgen_degree_centrality", - 3, 10, large_random_attachment_graph, |graph, _| degree_centrality(graph), @@ -115,7 +108,6 @@ pub fn graphgen_concomp(c: &mut Criterion) { graph_benchmark( c, "graphgen_concomp", - 5, 10, large_random_attachment_graph, |graph, _| weakly_connected_components(graph), @@ -126,7 +118,6 @@ pub fn graphgen_alternating_mask(c: &mut Criterion) { graph_benchmark( c, "graphgen_alternating_mask", - 3, 10, large_random_attachment_graph, |graph, _| alternating_mask(graph), @@ -137,7 +128,6 @@ pub fn graphgen_max_degree(c: &mut Criterion) { graph_benchmark( c, "graphgen_max_degree", - 3, 10, large_random_attachment_graph, |graph, _| max_degree(graph), @@ -148,7 +138,6 @@ pub fn graphgen_min_degree(c: &mut Criterion) { graph_benchmark( c, "graphgen_min_degree", - 3, 10, large_random_attachment_graph, |graph, _| min_degree(graph), @@ -159,7 +148,6 @@ pub fn graphgen_max_out_degree(c: &mut Criterion) { graph_benchmark( c, "graphgen_max_out_degree", - 3, 10, large_random_attachment_graph, |graph, _| max_out_degree(graph), @@ -170,7 +158,6 @@ pub fn graphgen_max_in_degree(c: &mut Criterion) { graph_benchmark( c, "graphgen_max_in_degree", - 3, 10, large_random_attachment_graph, |graph, _| max_in_degree(graph), @@ -181,7 +168,6 @@ pub fn graphgen_min_out_degree(c: &mut Criterion) { graph_benchmark( c, "graphgen_min_out_degree", - 3, 10, large_random_attachment_graph, |graph, _| min_out_degree(graph), @@ -192,7 +178,6 @@ pub fn graphgen_min_in_degree(c: &mut Criterion) { graph_benchmark( c, "graphgen_min_in_degree", - 3, 10, large_random_attachment_graph, |graph, _| min_in_degree(graph), @@ -203,7 +188,6 @@ pub fn graphgen_average_degree(c: &mut Criterion) { graph_benchmark( c, "graphgen_average_degree", - 3, 10, large_random_attachment_graph, |graph, _| average_degree(graph), @@ -214,7 +198,6 @@ pub fn graphgen_local_clustering_coefficient_batch(c: &mut Criterion) { graph_benchmark_with_setup( c, "graphgen_local_clustering_coefficient_batch", - 3, 10, large_random_attachment_graph, first_node_id, @@ -226,7 +209,6 @@ pub fn graphgen_temporally_reachable_nodes(c: &mut Criterion) { graph_benchmark_with_setup( c, "graphgen_temporally_reachable_nodes", - 3, 10, large_random_attachment_graph, first_node_id, @@ -238,7 +220,6 @@ pub fn graphgen_out_component(c: &mut Criterion) { graph_benchmark_with_setup( c, "graphgen_out_component", - 3, 10, large_random_attachment_graph, first_node_id, @@ -253,7 +234,6 @@ pub fn graphgen_out_component_filtered(c: &mut Criterion) { graph_benchmark_with_setup( c, "graphgen_out_component_filtered", - 3, 10, large_random_attachment_graph, first_node_id, @@ -268,7 +248,6 @@ pub fn graphgen_temporal_seir(c: &mut Criterion) { graph_benchmark( c, "graphgen_temporal_seir", - 3, 10, large_random_attachment_graph, |graph, _| { @@ -279,37 +258,37 @@ pub fn graphgen_temporal_seir(c: &mut Criterion) { } pub fn graphgen_internal_two_node_event(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_two_node_event", 2, 10, || { + simple_benchmark(c, "graphgen_internal_two_node_event", 10, || { two_node_event(1, 100) }) } pub fn graphgen_internal_init_two_node_count(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_init_two_node_count", 2, 10, || { + simple_benchmark(c, "graphgen_internal_init_two_node_count", 10, || { init_two_node_count() }) } pub fn graphgen_internal_star_event(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_star_event", 2, 10, || { + simple_benchmark(c, "graphgen_internal_star_event", 10, || { star_event(0, 1, 100) }) } pub fn graphgen_internal_init_star_count(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_init_star_count", 2, 10, || { + simple_benchmark(c, "graphgen_internal_init_star_count", 10, || { init_star_count(128) }) } pub fn graphgen_internal_new_triangle_edge(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_new_triangle_edge", 2, 10, || { + simple_benchmark(c, "graphgen_internal_new_triangle_edge", 10, || { new_triangle_edge(true, 1, 0, 1, 100) }) } pub fn graphgen_internal_init_tri_count(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_init_tri_count", 2, 10, || { + simple_benchmark(c, "graphgen_internal_init_tri_count", 10, || { init_tri_count(128) }) } diff --git a/raphtory-benchmark/benches/algobench_medium.rs b/raphtory-benchmark/benches/algobench_medium.rs index 3e3d32fbf9..a6da03b862 100644 --- a/raphtory-benchmark/benches/algobench_medium.rs +++ b/raphtory-benchmark/benches/algobench_medium.rs @@ -54,7 +54,6 @@ pub fn graphgen_clustering_coeff(c: &mut Criterion) { c, "graphgen_clustering_coeff", 10, - 10, medium_random_attachment_graph, |graph, _| global_clustering_coefficient(graph), ); @@ -65,7 +64,6 @@ pub fn graphgen_pagerank(c: &mut Criterion) { c, "graphgen_pagerank", 10, - 10, medium_random_attachment_graph, |graph, _| page_rank(graph, None, Some(100), None, None, true, None), ); @@ -73,7 +71,6 @@ pub fn graphgen_pagerank(c: &mut Criterion) { c, "graphgen_pagerank_subgraph", 10, - 10, medium_random_attachment_subgraph, |graph, _| page_rank(graph, None, Some(100), None, None, true, None), ); @@ -81,14 +78,12 @@ pub fn graphgen_pagerank(c: &mut Criterion) { c, "graphgen_pagerank_layered", 10, - 10, medium_random_attachment_layered, |graph, _| page_rank(graph, None, Some(100), None, None, true, None), ); graph_benchmark( c, "graphgen_pagerank_graph_filtered", - 20, 10, medium_random_attachment_filtered, |graph, _| page_rank(graph, None, Some(100), None, None, true, None), @@ -99,7 +94,6 @@ pub fn graphgen_hits(c: &mut Criterion) { graph_benchmark( c, "graphgen_hits", - 5, 10, medium_random_attachment_graph, |graph, _| hits(graph, 100, None), @@ -111,7 +105,6 @@ pub fn graphgen_triangle_count(c: &mut Criterion) { c, "graphgen_triangle_count", 10, - 10, medium_random_attachment_graph, |graph, _| triangle_count(graph, None), ); @@ -121,7 +114,6 @@ pub fn graphgen_triplet_count(c: &mut Criterion) { graph_benchmark( c, "graphgen_triplet_count", - 5, 10, medium_random_attachment_graph, |graph, _| triplet_count(graph, None), @@ -132,7 +124,6 @@ pub fn graphgen_reciprocity(c: &mut Criterion) { graph_benchmark( c, "graphgen_reciprocity", - 5, 10, medium_random_attachment_graph, |graph, _| global_reciprocity(graph), @@ -143,7 +134,6 @@ pub fn graphgen_scc(c: &mut Criterion) { graph_benchmark( c, "graphgen_scc", - 5, 10, medium_random_attachment_graph, |graph, _| strongly_connected_components(graph), @@ -154,7 +144,6 @@ pub fn graphgen_label_propagation(c: &mut Criterion) { graph_benchmark( c, "graphgen_label_propagation", - 20, 10, medium_random_attachment_graph, |graph, _| label_propagation(graph, 20, Some([1; 32]), None), @@ -165,7 +154,6 @@ pub fn graphgen_louvain(c: &mut Criterion) { graph_benchmark( c, "graphgen_louvain", - 20, 10, medium_random_attachment_graph, |graph, _| louvain::(graph, 1.0, None, None, Some(42)), @@ -176,7 +164,6 @@ pub fn graphgen_all_local_reciprocity(c: &mut Criterion) { graph_benchmark( c, "graphgen_all_local_reciprocity", - 5, 10, medium_random_attachment_graph, |graph, _| all_local_reciprocity(graph), @@ -187,7 +174,6 @@ pub fn graphgen_balance(c: &mut Criterion) { graph_benchmark( c, "graphgen_balance", - 5, 10, medium_weighted_random_attachment_graph, |graph, _| balance(graph, "weight".to_string(), Direction::BOTH).unwrap(), @@ -198,7 +184,6 @@ pub fn graphgen_temporal_motif_multi(c: &mut Criterion) { graph_benchmark( c, "graphgen_temporal_motif_multi", - 20, 10, medium_random_attachment_graph, |graph, _| temporal_three_node_motif_multi(graph, vec![100], None), @@ -209,7 +194,6 @@ pub fn graphgen_local_temporal_motif(c: &mut Criterion) { graph_benchmark( c, "graphgen_local_temporal_motif", - 20, 10, medium_random_attachment_graph, |graph, _| local_temporal_three_node_motif(graph, 100, None), @@ -220,7 +204,6 @@ pub fn graphgen_dijkstra(c: &mut Criterion) { graph_benchmark_with_setup( c, "graphgen_dijkstra", - 5, 10, medium_random_attachment_graph, first_node_id, @@ -241,7 +224,6 @@ pub fn graphgen_single_source_shortest_path(c: &mut Criterion) { graph_benchmark_with_setup( c, "graphgen_single_source_shortest_path", - 5, 10, medium_random_attachment_graph, first_node_id, @@ -253,7 +235,6 @@ pub fn graphgen_in_component(c: &mut Criterion) { graph_benchmark_with_setup( c, "graphgen_in_component", - 5, 10, medium_random_attachment_graph, first_node_id, @@ -268,7 +249,6 @@ pub fn graphgen_in_component_filtered(c: &mut Criterion) { graph_benchmark_with_setup( c, "graphgen_in_component_filtered", - 5, 10, medium_random_attachment_graph, first_node_id, @@ -284,7 +264,6 @@ pub fn graphgen_internal_global_triangle_motifs(c: &mut Criterion) { c, "graphgen_internal_global_triangle_motifs", 10, - 10, medium_random_attachment_graph, |graph, _| global_triangle_motifs_internal(graph, vec![100], None), ); @@ -295,7 +274,6 @@ pub fn graphgen_internal_local_triangle_motifs(c: &mut Criterion) { c, "graphgen_internal_local_triangle_motifs", 10, - 10, medium_random_attachment_graph, |graph, _| local_triangle_motifs_internal(graph, vec![100], None), ); @@ -305,7 +283,6 @@ pub fn graphgen_k_core_set(c: &mut Criterion) { graph_benchmark( c, "graphgen_k_core_set", - 5, 10, medium_random_attachment_graph, |graph, _| k_core_set(graph, 2, usize::MAX, None), @@ -316,7 +293,6 @@ pub fn graphgen_k_core(c: &mut Criterion) { graph_benchmark( c, "graphgen_k_core", - 5, 10, medium_random_attachment_graph, |graph, _| k_core(graph, 2, usize::MAX, None), @@ -328,7 +304,6 @@ pub fn graphgen_fast_rp(c: &mut Criterion) { c, "graphgen_fast_rp", 10, - 10, medium_random_attachment_graph, |graph, _| fast_rp(graph, 32, 0.5, vec![1.0, 1.0, 1.0], Some(1), None), ); @@ -338,7 +313,6 @@ pub fn graphgen_temporal_bipartite_projection(c: &mut Criterion) { graph_benchmark( c, "graphgen_temporal_bipartite_projection", - 20, 10, medium_typed_random_attachment_graph, |graph, _| temporal_bipartite_projection(graph, 1, "Right".to_string()), @@ -349,7 +323,6 @@ pub fn temporal_motifs(c: &mut Criterion) { graph_benchmark( c, "temporal_motifs", - 20, 10, medium_random_attachment_graph, |graph, _| global_temporal_three_node_motif(graph, 100, None), diff --git a/raphtory-benchmark/benches/algobench_slow.rs b/raphtory-benchmark/benches/algobench_slow.rs index 959e2c6222..5ef994d838 100644 --- a/raphtory-benchmark/benches/algobench_slow.rs +++ b/raphtory-benchmark/benches/algobench_slow.rs @@ -1,7 +1,7 @@ // Expensive algorithms (several hundred ms to multiple seconds per iteration on the // 5000-node large graph). Run against the much smaller 100-node tiny graph instead, to keep -// total suite runtime reasonable - these algorithms are already the ones most likely to time -// out criterion's sampling window even at that reduced scale. +// total suite runtime reasonable - at this scale they run in low milliseconds per iteration, +// so a short measurement window is enough to collect a stable sample. // // `betweenness_centrality` is this binary's representative for graph/subgraph/layered/filtered // view coverage; every other algorithm here only benchmarks the plain graph. @@ -32,7 +32,6 @@ pub fn graphgen_betweenness(c: &mut Criterion) { graph_benchmark( c, "graphgen_betweenness", - 20, 10, tiny_random_attachment_graph, |graph, _| betweenness_centrality(graph, None, false), @@ -40,7 +39,6 @@ pub fn graphgen_betweenness(c: &mut Criterion) { graph_benchmark( c, "graphgen_betweenness_subgraph", - 20, 10, tiny_random_attachment_subgraph, |graph, _| betweenness_centrality(graph, None, false), @@ -48,7 +46,6 @@ pub fn graphgen_betweenness(c: &mut Criterion) { graph_benchmark( c, "graphgen_betweenness_layered", - 20, 10, tiny_random_attachment_layered, |graph, _| betweenness_centrality(graph, None, false), @@ -56,7 +53,6 @@ pub fn graphgen_betweenness(c: &mut Criterion) { graph_benchmark( c, "graphgen_betweenness_graph_filtered", - 20, 10, tiny_random_attachment_filtered, |graph, _| betweenness_centrality(graph, None, false), @@ -67,7 +63,6 @@ pub fn graphgen_in_components(c: &mut Criterion) { graph_benchmark( c, "graphgen_in_components", - 20, 10, tiny_random_attachment_graph, |graph, _| in_components(graph, None), @@ -78,7 +73,6 @@ pub fn graphgen_out_components(c: &mut Criterion) { graph_benchmark( c, "graphgen_out_components", - 20, 10, tiny_random_attachment_graph, |graph, _| out_components(graph, None), @@ -89,7 +83,6 @@ pub fn graphgen_in_components_filtered(c: &mut Criterion) { graph_benchmark( c, "graphgen_in_components_filtered", - 20, 10, tiny_random_attachment_graph, |graph, _| in_components_filtered(graph, None, Unfiltered).unwrap(), @@ -100,7 +93,6 @@ pub fn graphgen_out_components_filtered(c: &mut Criterion) { graph_benchmark( c, "graphgen_out_components_filtered", - 20, 10, tiny_random_attachment_graph, |graph, _| out_components_filtered(graph, None, Unfiltered).unwrap(), @@ -111,7 +103,6 @@ pub fn graphgen_temporal_rich_club(c: &mut Criterion) { graph_benchmark( c, "graphgen_temporal_rich_club", - 20, 10, tiny_random_attachment_graph, |graph, _| { @@ -125,7 +116,6 @@ pub fn graphgen_fruchterman_reingold(c: &mut Criterion) { graph_benchmark( c, "graphgen_fruchterman_reingold", - 20, 10, tiny_random_attachment_graph, |graph, _| fruchterman_reingold_unbounded(graph, 5, 1.0, 1.0, 0.9, 0.1), @@ -136,7 +126,6 @@ pub fn graphgen_cohesive_fruchterman_reingold(c: &mut Criterion) { graph_benchmark( c, "graphgen_cohesive_fruchterman_reingold", - 20, 10, tiny_random_attachment_graph, |graph, _| cohesive_fruchterman_reingold(graph, 5, 1.0, 1.0, 0.9, 0.1), @@ -147,7 +136,6 @@ pub fn graphgen_max_weight_matching(c: &mut Criterion) { graph_benchmark( c, "graphgen_max_weight_matching", - 20, 10, tiny_random_attachment_graph, |graph, _| max_weight_matching(graph, None, false, false), diff --git a/raphtory-benchmark/src/algobench_common.rs b/raphtory-benchmark/src/algobench_common.rs index fcb83b2838..6f649879fb 100644 --- a/raphtory-benchmark/src/algobench_common.rs +++ b/raphtory-benchmark/src/algobench_common.rs @@ -28,12 +28,22 @@ use raphtory::{ graphgen::random_attachment::random_attachment, prelude::*, }; -use std::{hint::black_box, sync::OnceLock}; +use std::{ + hint::black_box, + sync::OnceLock, + time::{Duration, Instant}, +}; + +// Criterion normally chooses how many times to call the benchmarked routine per sample based +// on the measurement time budget, which is what let algobench_slow balloon to 500-1,000 real +// algorithm calls per benchmark even with a short measurement window. Pinning this instead +// guarantees every algobench benchmark does exactly `sample_size * ITERS_PER_SAMPLE` real runs +// of the algorithm, independent of how Criterion's timing estimate comes out. +const ITERS_PER_SAMPLE: u64 = 10; pub fn graph_benchmark_with_setup( c: &mut Criterion, name: &str, - measurement_secs: u64, sample_size: usize, build_graph: BuildGraph, setup: Setup, @@ -49,12 +59,16 @@ pub fn graph_benchmark_with_setup( let setup_data = setup(&graph); group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(measurement_secs)); + group.warm_up_time(Duration::from_millis(200)); group.sample_size(sample_size); group.bench_function(name, |b| { - b.iter(|| { - let result = run(&graph, &setup_data); - black_box(result); + b.iter_custom(|iters| { + let start = Instant::now(); + for _ in 0..ITERS_PER_SAMPLE { + let result = run(&graph, &setup_data); + black_box(result); + } + start.elapsed().mul_f64(iters as f64 / ITERS_PER_SAMPLE as f64) }); }); group.finish() @@ -63,7 +77,6 @@ pub fn graph_benchmark_with_setup( pub fn graph_benchmark( c: &mut Criterion, name: &str, - measurement_secs: u64, sample_size: usize, build_graph: BuildGraph, run: Run, @@ -72,21 +85,12 @@ pub fn graph_benchmark( BuildGraph: FnOnce() -> G, Run: FnMut(&G, &()) -> Output, { - graph_benchmark_with_setup( - c, - name, - measurement_secs, - sample_size, - build_graph, - |_| (), - run, - ) + graph_benchmark_with_setup(c, name, sample_size, build_graph, |_| (), run) } pub fn simple_benchmark( c: &mut Criterion, name: &str, - measurement_secs: u64, sample_size: usize, mut run: Run, ) where @@ -94,12 +98,16 @@ pub fn simple_benchmark( { let mut group = c.benchmark_group(name); group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(measurement_secs)); + group.warm_up_time(Duration::from_millis(200)); group.sample_size(sample_size); group.bench_function(name, |b| { - b.iter(|| { - let result = run(); - black_box(result); + b.iter_custom(|iters| { + let start = Instant::now(); + for _ in 0..ITERS_PER_SAMPLE { + let result = run(); + black_box(result); + } + start.elapsed().mul_f64(iters as f64 / ITERS_PER_SAMPLE as f64) }); }); group.finish() @@ -188,7 +196,7 @@ pub fn large_typed_random_attachment_graph() -> Graph { pub fn build_medium_random_attachment_graph() -> Graph { let graph = Graph::new(); let seed: [u8; 32] = [1; 32]; - random_attachment(&graph, 1500, 4, Some(seed)); + random_attachment(&graph, 5000, 4, Some(seed)); graph } @@ -257,7 +265,7 @@ pub fn medium_typed_random_attachment_graph() -> Graph { pub fn build_tiny_random_attachment_graph() -> Graph { let graph = Graph::new(); let seed: [u8; 32] = [1; 32]; - random_attachment(&graph, 100, 4, Some(seed)); + random_attachment(&graph, 5000, 4, Some(seed)); graph } From bdb06d2960ecefc5a7c3ac0c5b935daa9e36b338 Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Wed, 5 Aug 2026 09:48:15 -0500 Subject: [PATCH 20/24] Revert "wip" This reverts commit 292972e3989ffbd54da0a1188c1d82c63b97d574. --- raphtory-benchmark/benches/algobench_fast.rs | 33 +++++++++--- .../benches/algobench_medium.rs | 27 ++++++++++ raphtory-benchmark/benches/algobench_slow.rs | 16 +++++- raphtory-benchmark/src/algobench_common.rs | 54 ++++++++----------- 4 files changed, 91 insertions(+), 39 deletions(-) diff --git a/raphtory-benchmark/benches/algobench_fast.rs b/raphtory-benchmark/benches/algobench_fast.rs index 5126c3b6ac..554b869f56 100644 --- a/raphtory-benchmark/benches/algobench_fast.rs +++ b/raphtory-benchmark/benches/algobench_fast.rs @@ -45,6 +45,7 @@ pub fn local_triangle_count_analysis(c: &mut Criterion) { graph_benchmark_with_setup( c, "local_triangle_count", + 3, 10, large_random_attachment_graph, first_node_id, @@ -56,6 +57,7 @@ pub fn local_clustering_coefficient_analysis(c: &mut Criterion) { graph_benchmark_with_setup( c, "local_clustering_coefficient", + 3, 10, large_random_attachment_graph, first_node_id, @@ -67,6 +69,7 @@ pub fn graphgen_directed_density(c: &mut Criterion) { graph_benchmark( c, "graphgen_directed_density", + 2, 10, large_random_attachment_graph, |graph, _| directed_graph_density(graph), @@ -74,6 +77,7 @@ pub fn graphgen_directed_density(c: &mut Criterion) { graph_benchmark( c, "graphgen_directed_density_subgraph", + 3, 10, large_random_attachment_subgraph, |graph, _| directed_graph_density(graph), @@ -81,6 +85,7 @@ pub fn graphgen_directed_density(c: &mut Criterion) { graph_benchmark( c, "graphgen_directed_density_layered", + 3, 10, large_random_attachment_layered, |graph, _| directed_graph_density(graph), @@ -88,6 +93,7 @@ pub fn graphgen_directed_density(c: &mut Criterion) { graph_benchmark( c, "graphgen_directed_density_graph_filtered", + 5, 10, large_random_attachment_filtered, |graph, _| directed_graph_density(graph), @@ -98,6 +104,7 @@ pub fn graphgen_degree_centrality(c: &mut Criterion) { graph_benchmark( c, "graphgen_degree_centrality", + 3, 10, large_random_attachment_graph, |graph, _| degree_centrality(graph), @@ -108,6 +115,7 @@ pub fn graphgen_concomp(c: &mut Criterion) { graph_benchmark( c, "graphgen_concomp", + 5, 10, large_random_attachment_graph, |graph, _| weakly_connected_components(graph), @@ -118,6 +126,7 @@ pub fn graphgen_alternating_mask(c: &mut Criterion) { graph_benchmark( c, "graphgen_alternating_mask", + 3, 10, large_random_attachment_graph, |graph, _| alternating_mask(graph), @@ -128,6 +137,7 @@ pub fn graphgen_max_degree(c: &mut Criterion) { graph_benchmark( c, "graphgen_max_degree", + 3, 10, large_random_attachment_graph, |graph, _| max_degree(graph), @@ -138,6 +148,7 @@ pub fn graphgen_min_degree(c: &mut Criterion) { graph_benchmark( c, "graphgen_min_degree", + 3, 10, large_random_attachment_graph, |graph, _| min_degree(graph), @@ -148,6 +159,7 @@ pub fn graphgen_max_out_degree(c: &mut Criterion) { graph_benchmark( c, "graphgen_max_out_degree", + 3, 10, large_random_attachment_graph, |graph, _| max_out_degree(graph), @@ -158,6 +170,7 @@ pub fn graphgen_max_in_degree(c: &mut Criterion) { graph_benchmark( c, "graphgen_max_in_degree", + 3, 10, large_random_attachment_graph, |graph, _| max_in_degree(graph), @@ -168,6 +181,7 @@ pub fn graphgen_min_out_degree(c: &mut Criterion) { graph_benchmark( c, "graphgen_min_out_degree", + 3, 10, large_random_attachment_graph, |graph, _| min_out_degree(graph), @@ -178,6 +192,7 @@ pub fn graphgen_min_in_degree(c: &mut Criterion) { graph_benchmark( c, "graphgen_min_in_degree", + 3, 10, large_random_attachment_graph, |graph, _| min_in_degree(graph), @@ -188,6 +203,7 @@ pub fn graphgen_average_degree(c: &mut Criterion) { graph_benchmark( c, "graphgen_average_degree", + 3, 10, large_random_attachment_graph, |graph, _| average_degree(graph), @@ -198,6 +214,7 @@ pub fn graphgen_local_clustering_coefficient_batch(c: &mut Criterion) { graph_benchmark_with_setup( c, "graphgen_local_clustering_coefficient_batch", + 3, 10, large_random_attachment_graph, first_node_id, @@ -209,6 +226,7 @@ pub fn graphgen_temporally_reachable_nodes(c: &mut Criterion) { graph_benchmark_with_setup( c, "graphgen_temporally_reachable_nodes", + 3, 10, large_random_attachment_graph, first_node_id, @@ -220,6 +238,7 @@ pub fn graphgen_out_component(c: &mut Criterion) { graph_benchmark_with_setup( c, "graphgen_out_component", + 3, 10, large_random_attachment_graph, first_node_id, @@ -234,6 +253,7 @@ pub fn graphgen_out_component_filtered(c: &mut Criterion) { graph_benchmark_with_setup( c, "graphgen_out_component_filtered", + 3, 10, large_random_attachment_graph, first_node_id, @@ -248,6 +268,7 @@ pub fn graphgen_temporal_seir(c: &mut Criterion) { graph_benchmark( c, "graphgen_temporal_seir", + 3, 10, large_random_attachment_graph, |graph, _| { @@ -258,37 +279,37 @@ pub fn graphgen_temporal_seir(c: &mut Criterion) { } pub fn graphgen_internal_two_node_event(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_two_node_event", 10, || { + simple_benchmark(c, "graphgen_internal_two_node_event", 2, 10, || { two_node_event(1, 100) }) } pub fn graphgen_internal_init_two_node_count(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_init_two_node_count", 10, || { + simple_benchmark(c, "graphgen_internal_init_two_node_count", 2, 10, || { init_two_node_count() }) } pub fn graphgen_internal_star_event(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_star_event", 10, || { + simple_benchmark(c, "graphgen_internal_star_event", 2, 10, || { star_event(0, 1, 100) }) } pub fn graphgen_internal_init_star_count(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_init_star_count", 10, || { + simple_benchmark(c, "graphgen_internal_init_star_count", 2, 10, || { init_star_count(128) }) } pub fn graphgen_internal_new_triangle_edge(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_new_triangle_edge", 10, || { + simple_benchmark(c, "graphgen_internal_new_triangle_edge", 2, 10, || { new_triangle_edge(true, 1, 0, 1, 100) }) } pub fn graphgen_internal_init_tri_count(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_init_tri_count", 10, || { + simple_benchmark(c, "graphgen_internal_init_tri_count", 2, 10, || { init_tri_count(128) }) } diff --git a/raphtory-benchmark/benches/algobench_medium.rs b/raphtory-benchmark/benches/algobench_medium.rs index a6da03b862..3e3d32fbf9 100644 --- a/raphtory-benchmark/benches/algobench_medium.rs +++ b/raphtory-benchmark/benches/algobench_medium.rs @@ -54,6 +54,7 @@ pub fn graphgen_clustering_coeff(c: &mut Criterion) { c, "graphgen_clustering_coeff", 10, + 10, medium_random_attachment_graph, |graph, _| global_clustering_coefficient(graph), ); @@ -64,6 +65,7 @@ pub fn graphgen_pagerank(c: &mut Criterion) { c, "graphgen_pagerank", 10, + 10, medium_random_attachment_graph, |graph, _| page_rank(graph, None, Some(100), None, None, true, None), ); @@ -71,6 +73,7 @@ pub fn graphgen_pagerank(c: &mut Criterion) { c, "graphgen_pagerank_subgraph", 10, + 10, medium_random_attachment_subgraph, |graph, _| page_rank(graph, None, Some(100), None, None, true, None), ); @@ -78,12 +81,14 @@ pub fn graphgen_pagerank(c: &mut Criterion) { c, "graphgen_pagerank_layered", 10, + 10, medium_random_attachment_layered, |graph, _| page_rank(graph, None, Some(100), None, None, true, None), ); graph_benchmark( c, "graphgen_pagerank_graph_filtered", + 20, 10, medium_random_attachment_filtered, |graph, _| page_rank(graph, None, Some(100), None, None, true, None), @@ -94,6 +99,7 @@ pub fn graphgen_hits(c: &mut Criterion) { graph_benchmark( c, "graphgen_hits", + 5, 10, medium_random_attachment_graph, |graph, _| hits(graph, 100, None), @@ -105,6 +111,7 @@ pub fn graphgen_triangle_count(c: &mut Criterion) { c, "graphgen_triangle_count", 10, + 10, medium_random_attachment_graph, |graph, _| triangle_count(graph, None), ); @@ -114,6 +121,7 @@ pub fn graphgen_triplet_count(c: &mut Criterion) { graph_benchmark( c, "graphgen_triplet_count", + 5, 10, medium_random_attachment_graph, |graph, _| triplet_count(graph, None), @@ -124,6 +132,7 @@ pub fn graphgen_reciprocity(c: &mut Criterion) { graph_benchmark( c, "graphgen_reciprocity", + 5, 10, medium_random_attachment_graph, |graph, _| global_reciprocity(graph), @@ -134,6 +143,7 @@ pub fn graphgen_scc(c: &mut Criterion) { graph_benchmark( c, "graphgen_scc", + 5, 10, medium_random_attachment_graph, |graph, _| strongly_connected_components(graph), @@ -144,6 +154,7 @@ pub fn graphgen_label_propagation(c: &mut Criterion) { graph_benchmark( c, "graphgen_label_propagation", + 20, 10, medium_random_attachment_graph, |graph, _| label_propagation(graph, 20, Some([1; 32]), None), @@ -154,6 +165,7 @@ pub fn graphgen_louvain(c: &mut Criterion) { graph_benchmark( c, "graphgen_louvain", + 20, 10, medium_random_attachment_graph, |graph, _| louvain::(graph, 1.0, None, None, Some(42)), @@ -164,6 +176,7 @@ pub fn graphgen_all_local_reciprocity(c: &mut Criterion) { graph_benchmark( c, "graphgen_all_local_reciprocity", + 5, 10, medium_random_attachment_graph, |graph, _| all_local_reciprocity(graph), @@ -174,6 +187,7 @@ pub fn graphgen_balance(c: &mut Criterion) { graph_benchmark( c, "graphgen_balance", + 5, 10, medium_weighted_random_attachment_graph, |graph, _| balance(graph, "weight".to_string(), Direction::BOTH).unwrap(), @@ -184,6 +198,7 @@ pub fn graphgen_temporal_motif_multi(c: &mut Criterion) { graph_benchmark( c, "graphgen_temporal_motif_multi", + 20, 10, medium_random_attachment_graph, |graph, _| temporal_three_node_motif_multi(graph, vec![100], None), @@ -194,6 +209,7 @@ pub fn graphgen_local_temporal_motif(c: &mut Criterion) { graph_benchmark( c, "graphgen_local_temporal_motif", + 20, 10, medium_random_attachment_graph, |graph, _| local_temporal_three_node_motif(graph, 100, None), @@ -204,6 +220,7 @@ pub fn graphgen_dijkstra(c: &mut Criterion) { graph_benchmark_with_setup( c, "graphgen_dijkstra", + 5, 10, medium_random_attachment_graph, first_node_id, @@ -224,6 +241,7 @@ pub fn graphgen_single_source_shortest_path(c: &mut Criterion) { graph_benchmark_with_setup( c, "graphgen_single_source_shortest_path", + 5, 10, medium_random_attachment_graph, first_node_id, @@ -235,6 +253,7 @@ pub fn graphgen_in_component(c: &mut Criterion) { graph_benchmark_with_setup( c, "graphgen_in_component", + 5, 10, medium_random_attachment_graph, first_node_id, @@ -249,6 +268,7 @@ pub fn graphgen_in_component_filtered(c: &mut Criterion) { graph_benchmark_with_setup( c, "graphgen_in_component_filtered", + 5, 10, medium_random_attachment_graph, first_node_id, @@ -264,6 +284,7 @@ pub fn graphgen_internal_global_triangle_motifs(c: &mut Criterion) { c, "graphgen_internal_global_triangle_motifs", 10, + 10, medium_random_attachment_graph, |graph, _| global_triangle_motifs_internal(graph, vec![100], None), ); @@ -274,6 +295,7 @@ pub fn graphgen_internal_local_triangle_motifs(c: &mut Criterion) { c, "graphgen_internal_local_triangle_motifs", 10, + 10, medium_random_attachment_graph, |graph, _| local_triangle_motifs_internal(graph, vec![100], None), ); @@ -283,6 +305,7 @@ pub fn graphgen_k_core_set(c: &mut Criterion) { graph_benchmark( c, "graphgen_k_core_set", + 5, 10, medium_random_attachment_graph, |graph, _| k_core_set(graph, 2, usize::MAX, None), @@ -293,6 +316,7 @@ pub fn graphgen_k_core(c: &mut Criterion) { graph_benchmark( c, "graphgen_k_core", + 5, 10, medium_random_attachment_graph, |graph, _| k_core(graph, 2, usize::MAX, None), @@ -304,6 +328,7 @@ pub fn graphgen_fast_rp(c: &mut Criterion) { c, "graphgen_fast_rp", 10, + 10, medium_random_attachment_graph, |graph, _| fast_rp(graph, 32, 0.5, vec![1.0, 1.0, 1.0], Some(1), None), ); @@ -313,6 +338,7 @@ pub fn graphgen_temporal_bipartite_projection(c: &mut Criterion) { graph_benchmark( c, "graphgen_temporal_bipartite_projection", + 20, 10, medium_typed_random_attachment_graph, |graph, _| temporal_bipartite_projection(graph, 1, "Right".to_string()), @@ -323,6 +349,7 @@ pub fn temporal_motifs(c: &mut Criterion) { graph_benchmark( c, "temporal_motifs", + 20, 10, medium_random_attachment_graph, |graph, _| global_temporal_three_node_motif(graph, 100, None), diff --git a/raphtory-benchmark/benches/algobench_slow.rs b/raphtory-benchmark/benches/algobench_slow.rs index 5ef994d838..959e2c6222 100644 --- a/raphtory-benchmark/benches/algobench_slow.rs +++ b/raphtory-benchmark/benches/algobench_slow.rs @@ -1,7 +1,7 @@ // Expensive algorithms (several hundred ms to multiple seconds per iteration on the // 5000-node large graph). Run against the much smaller 100-node tiny graph instead, to keep -// total suite runtime reasonable - at this scale they run in low milliseconds per iteration, -// so a short measurement window is enough to collect a stable sample. +// total suite runtime reasonable - these algorithms are already the ones most likely to time +// out criterion's sampling window even at that reduced scale. // // `betweenness_centrality` is this binary's representative for graph/subgraph/layered/filtered // view coverage; every other algorithm here only benchmarks the plain graph. @@ -32,6 +32,7 @@ pub fn graphgen_betweenness(c: &mut Criterion) { graph_benchmark( c, "graphgen_betweenness", + 20, 10, tiny_random_attachment_graph, |graph, _| betweenness_centrality(graph, None, false), @@ -39,6 +40,7 @@ pub fn graphgen_betweenness(c: &mut Criterion) { graph_benchmark( c, "graphgen_betweenness_subgraph", + 20, 10, tiny_random_attachment_subgraph, |graph, _| betweenness_centrality(graph, None, false), @@ -46,6 +48,7 @@ pub fn graphgen_betweenness(c: &mut Criterion) { graph_benchmark( c, "graphgen_betweenness_layered", + 20, 10, tiny_random_attachment_layered, |graph, _| betweenness_centrality(graph, None, false), @@ -53,6 +56,7 @@ pub fn graphgen_betweenness(c: &mut Criterion) { graph_benchmark( c, "graphgen_betweenness_graph_filtered", + 20, 10, tiny_random_attachment_filtered, |graph, _| betweenness_centrality(graph, None, false), @@ -63,6 +67,7 @@ pub fn graphgen_in_components(c: &mut Criterion) { graph_benchmark( c, "graphgen_in_components", + 20, 10, tiny_random_attachment_graph, |graph, _| in_components(graph, None), @@ -73,6 +78,7 @@ pub fn graphgen_out_components(c: &mut Criterion) { graph_benchmark( c, "graphgen_out_components", + 20, 10, tiny_random_attachment_graph, |graph, _| out_components(graph, None), @@ -83,6 +89,7 @@ pub fn graphgen_in_components_filtered(c: &mut Criterion) { graph_benchmark( c, "graphgen_in_components_filtered", + 20, 10, tiny_random_attachment_graph, |graph, _| in_components_filtered(graph, None, Unfiltered).unwrap(), @@ -93,6 +100,7 @@ pub fn graphgen_out_components_filtered(c: &mut Criterion) { graph_benchmark( c, "graphgen_out_components_filtered", + 20, 10, tiny_random_attachment_graph, |graph, _| out_components_filtered(graph, None, Unfiltered).unwrap(), @@ -103,6 +111,7 @@ pub fn graphgen_temporal_rich_club(c: &mut Criterion) { graph_benchmark( c, "graphgen_temporal_rich_club", + 20, 10, tiny_random_attachment_graph, |graph, _| { @@ -116,6 +125,7 @@ pub fn graphgen_fruchterman_reingold(c: &mut Criterion) { graph_benchmark( c, "graphgen_fruchterman_reingold", + 20, 10, tiny_random_attachment_graph, |graph, _| fruchterman_reingold_unbounded(graph, 5, 1.0, 1.0, 0.9, 0.1), @@ -126,6 +136,7 @@ pub fn graphgen_cohesive_fruchterman_reingold(c: &mut Criterion) { graph_benchmark( c, "graphgen_cohesive_fruchterman_reingold", + 20, 10, tiny_random_attachment_graph, |graph, _| cohesive_fruchterman_reingold(graph, 5, 1.0, 1.0, 0.9, 0.1), @@ -136,6 +147,7 @@ pub fn graphgen_max_weight_matching(c: &mut Criterion) { graph_benchmark( c, "graphgen_max_weight_matching", + 20, 10, tiny_random_attachment_graph, |graph, _| max_weight_matching(graph, None, false, false), diff --git a/raphtory-benchmark/src/algobench_common.rs b/raphtory-benchmark/src/algobench_common.rs index 6f649879fb..fcb83b2838 100644 --- a/raphtory-benchmark/src/algobench_common.rs +++ b/raphtory-benchmark/src/algobench_common.rs @@ -28,22 +28,12 @@ use raphtory::{ graphgen::random_attachment::random_attachment, prelude::*, }; -use std::{ - hint::black_box, - sync::OnceLock, - time::{Duration, Instant}, -}; - -// Criterion normally chooses how many times to call the benchmarked routine per sample based -// on the measurement time budget, which is what let algobench_slow balloon to 500-1,000 real -// algorithm calls per benchmark even with a short measurement window. Pinning this instead -// guarantees every algobench benchmark does exactly `sample_size * ITERS_PER_SAMPLE` real runs -// of the algorithm, independent of how Criterion's timing estimate comes out. -const ITERS_PER_SAMPLE: u64 = 10; +use std::{hint::black_box, sync::OnceLock}; pub fn graph_benchmark_with_setup( c: &mut Criterion, name: &str, + measurement_secs: u64, sample_size: usize, build_graph: BuildGraph, setup: Setup, @@ -59,16 +49,12 @@ pub fn graph_benchmark_with_setup( let setup_data = setup(&graph); group.sampling_mode(SamplingMode::Flat); - group.warm_up_time(Duration::from_millis(200)); + group.measurement_time(std::time::Duration::from_secs(measurement_secs)); group.sample_size(sample_size); group.bench_function(name, |b| { - b.iter_custom(|iters| { - let start = Instant::now(); - for _ in 0..ITERS_PER_SAMPLE { - let result = run(&graph, &setup_data); - black_box(result); - } - start.elapsed().mul_f64(iters as f64 / ITERS_PER_SAMPLE as f64) + b.iter(|| { + let result = run(&graph, &setup_data); + black_box(result); }); }); group.finish() @@ -77,6 +63,7 @@ pub fn graph_benchmark_with_setup( pub fn graph_benchmark( c: &mut Criterion, name: &str, + measurement_secs: u64, sample_size: usize, build_graph: BuildGraph, run: Run, @@ -85,12 +72,21 @@ pub fn graph_benchmark( BuildGraph: FnOnce() -> G, Run: FnMut(&G, &()) -> Output, { - graph_benchmark_with_setup(c, name, sample_size, build_graph, |_| (), run) + graph_benchmark_with_setup( + c, + name, + measurement_secs, + sample_size, + build_graph, + |_| (), + run, + ) } pub fn simple_benchmark( c: &mut Criterion, name: &str, + measurement_secs: u64, sample_size: usize, mut run: Run, ) where @@ -98,16 +94,12 @@ pub fn simple_benchmark( { let mut group = c.benchmark_group(name); group.sampling_mode(SamplingMode::Flat); - group.warm_up_time(Duration::from_millis(200)); + group.measurement_time(std::time::Duration::from_secs(measurement_secs)); group.sample_size(sample_size); group.bench_function(name, |b| { - b.iter_custom(|iters| { - let start = Instant::now(); - for _ in 0..ITERS_PER_SAMPLE { - let result = run(); - black_box(result); - } - start.elapsed().mul_f64(iters as f64 / ITERS_PER_SAMPLE as f64) + b.iter(|| { + let result = run(); + black_box(result); }); }); group.finish() @@ -196,7 +188,7 @@ pub fn large_typed_random_attachment_graph() -> Graph { pub fn build_medium_random_attachment_graph() -> Graph { let graph = Graph::new(); let seed: [u8; 32] = [1; 32]; - random_attachment(&graph, 5000, 4, Some(seed)); + random_attachment(&graph, 1500, 4, Some(seed)); graph } @@ -265,7 +257,7 @@ pub fn medium_typed_random_attachment_graph() -> Graph { pub fn build_tiny_random_attachment_graph() -> Graph { let graph = Graph::new(); let seed: [u8; 32] = [1; 32]; - random_attachment(&graph, 5000, 4, Some(seed)); + random_attachment(&graph, 100, 4, Some(seed)); graph } From 7d712fdf99e02dcff7b70f69171fb00149e545d3 Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Wed, 5 Aug 2026 11:22:41 -0500 Subject: [PATCH 21/24] fix deadlocks --- raphtory-benchmark/benches/algobench_medium.rs | 5 +---- raphtory-benchmark/src/algobench_common.rs | 8 +++++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/raphtory-benchmark/benches/algobench_medium.rs b/raphtory-benchmark/benches/algobench_medium.rs index 3e3d32fbf9..6e0e05a5a1 100644 --- a/raphtory-benchmark/benches/algobench_medium.rs +++ b/raphtory-benchmark/benches/algobench_medium.rs @@ -43,10 +43,7 @@ use raphtory::{ use criterion::{criterion_group, criterion_main, Criterion}; use raphtory_api::core::Direction; use raphtory_benchmark::algobench_common::{ - first_node_id, graph_benchmark, graph_benchmark_with_setup, medium_random_attachment_filtered, - medium_random_attachment_graph, medium_random_attachment_layered, - medium_random_attachment_subgraph, medium_typed_random_attachment_graph, - medium_weighted_random_attachment_graph, + first_node_id, graph_benchmark, graph_benchmark_with_setup, medium_random_attachment_filtered, medium_random_attachment_graph, medium_random_attachment_layered, medium_random_attachment_subgraph, medium_typed_random_attachment_graph, medium_weighted_random_attachment_graph, }; pub fn graphgen_clustering_coeff(c: &mut Criterion) { diff --git a/raphtory-benchmark/src/algobench_common.rs b/raphtory-benchmark/src/algobench_common.rs index fcb83b2838..770eda2a9d 100644 --- a/raphtory-benchmark/src/algobench_common.rs +++ b/raphtory-benchmark/src/algobench_common.rs @@ -57,7 +57,7 @@ pub fn graph_benchmark_with_setup( black_box(result); }); }); - group.finish() + group.finish(); } pub fn graph_benchmark( @@ -166,7 +166,8 @@ pub fn large_weighted_random_attachment_graph() -> Graph { pub fn build_large_typed_random_attachment_graph() -> Graph { let graph = build_large_random_attachment_graph(); - for id in graph.nodes().id().iter_values() { + let ids = graph.nodes().id().iter_values().collect::>(); + for id in ids { graph .add_node(0, id, NO_PROPS, Some("Right"), None) .expect("unable to set node type"); @@ -236,7 +237,8 @@ pub fn medium_weighted_random_attachment_graph() -> Graph { pub fn build_medium_typed_random_attachment_graph() -> Graph { let graph = build_medium_random_attachment_graph(); - for id in graph.nodes().id().iter_values() { + let ids = graph.nodes().id().iter_values().collect::>(); + for id in ids { graph .add_node(0, id, NO_PROPS, Some("Right"), None) .expect("unable to set node type"); From 2979a84c5cd129e99e0dd646b915b5e3a625ba1f Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Thu, 6 Aug 2026 08:54:25 -0500 Subject: [PATCH 22/24] got rid of internal benchmarks and other unecessary things --- raphtory-benchmark/benches/algobench_fast.rs | 68 +------------------ .../benches/algobench_medium.rs | 7 -- raphtory-benchmark/benches/algobench_slow.rs | 8 --- raphtory-benchmark/src/algobench_common.rs | 55 ++------------- 4 files changed, 6 insertions(+), 132 deletions(-) diff --git a/raphtory-benchmark/benches/algobench_fast.rs b/raphtory-benchmark/benches/algobench_fast.rs index 554b869f56..5058434ab4 100644 --- a/raphtory-benchmark/benches/algobench_fast.rs +++ b/raphtory-benchmark/benches/algobench_fast.rs @@ -1,11 +1,5 @@ -// Trivial / fast algorithms (sub-millisecond to ~1ms on the 5000-node large graph). -// -// `directed_graph_density` is this binary's representative for graph/subgraph/layered/filtered -// view coverage; every other algorithm here only benchmarks the plain graph. - use raphtory::{ algorithms::{ - alternating_mask::alternating_mask, centrality::degree_centrality::degree_centrality, components::{out_component, out_component_filtered}, metrics::{ @@ -20,11 +14,7 @@ use raphtory::{ directed_graph_density::directed_graph_density, }, motifs::{ - local_triangle_count::local_triangle_count, - three_node_motifs::{ - init_star_count, init_tri_count, init_two_node_count, new_triangle_edge, - star_event, two_node_event, - }, + local_triangle_count::local_triangle_count }, pathing::temporal_reachability::temporally_reachable_nodes, components::weakly_connected_components, @@ -38,7 +28,7 @@ use rand::{rngs::SmallRng, SeedableRng}; use raphtory_benchmark::algobench_common::{ first_node_id, graph_benchmark, graph_benchmark_with_setup, large_random_attachment_filtered, large_random_attachment_graph, large_random_attachment_layered, - large_random_attachment_subgraph, simple_benchmark, + large_random_attachment_subgraph }; pub fn local_triangle_count_analysis(c: &mut Criterion) { @@ -122,17 +112,6 @@ pub fn graphgen_concomp(c: &mut Criterion) { ); } -pub fn graphgen_alternating_mask(c: &mut Criterion) { - graph_benchmark( - c, - "graphgen_alternating_mask", - 3, - 10, - large_random_attachment_graph, - |graph, _| alternating_mask(graph), - ); -} - pub fn graphgen_max_degree(c: &mut Criterion) { graph_benchmark( c, @@ -278,42 +257,6 @@ pub fn graphgen_temporal_seir(c: &mut Criterion) { ); } -pub fn graphgen_internal_two_node_event(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_two_node_event", 2, 10, || { - two_node_event(1, 100) - }) -} - -pub fn graphgen_internal_init_two_node_count(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_init_two_node_count", 2, 10, || { - init_two_node_count() - }) -} - -pub fn graphgen_internal_star_event(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_star_event", 2, 10, || { - star_event(0, 1, 100) - }) -} - -pub fn graphgen_internal_init_star_count(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_init_star_count", 2, 10, || { - init_star_count(128) - }) -} - -pub fn graphgen_internal_new_triangle_edge(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_new_triangle_edge", 2, 10, || { - new_triangle_edge(true, 1, 0, 1, 100) - }) -} - -pub fn graphgen_internal_init_tri_count(c: &mut Criterion) { - simple_benchmark(c, "graphgen_internal_init_tri_count", 2, 10, || { - init_tri_count(128) - }) -} - criterion_group!( benches, local_triangle_count_analysis, @@ -321,7 +264,6 @@ criterion_group!( graphgen_directed_density, graphgen_degree_centrality, graphgen_concomp, - graphgen_alternating_mask, graphgen_max_degree, graphgen_min_degree, graphgen_max_out_degree, @@ -334,11 +276,5 @@ criterion_group!( graphgen_out_component, graphgen_out_component_filtered, graphgen_temporal_seir, - graphgen_internal_two_node_event, - graphgen_internal_init_two_node_count, - graphgen_internal_star_event, - graphgen_internal_init_star_count, - graphgen_internal_new_triangle_edge, - graphgen_internal_init_tri_count, ); criterion_main!(benches); diff --git a/raphtory-benchmark/benches/algobench_medium.rs b/raphtory-benchmark/benches/algobench_medium.rs index 6e0e05a5a1..7ea6974ce2 100644 --- a/raphtory-benchmark/benches/algobench_medium.rs +++ b/raphtory-benchmark/benches/algobench_medium.rs @@ -1,10 +1,3 @@ -// Medium complexity algorithms (roughly ~1ms - 200ms), run against a dedicated 1500-node -// medium graph rather than the large (5000 node) or tiny (100 node) graphs used by the -// fast/slow tiers. -// -// `pagerank` is this binary's representative for graph/subgraph/layered/filtered view -// coverage; every other algorithm here only benchmarks the plain graph. - use raphtory::{ algorithms::{ centrality::{hits::hits, pagerank::page_rank}, diff --git a/raphtory-benchmark/benches/algobench_slow.rs b/raphtory-benchmark/benches/algobench_slow.rs index 959e2c6222..22f1bbacd7 100644 --- a/raphtory-benchmark/benches/algobench_slow.rs +++ b/raphtory-benchmark/benches/algobench_slow.rs @@ -1,11 +1,3 @@ -// Expensive algorithms (several hundred ms to multiple seconds per iteration on the -// 5000-node large graph). Run against the much smaller 100-node tiny graph instead, to keep -// total suite runtime reasonable - these algorithms are already the ones most likely to time -// out criterion's sampling window even at that reduced scale. -// -// `betweenness_centrality` is this binary's representative for graph/subgraph/layered/filtered -// view coverage; every other algorithm here only benchmarks the plain graph. - use raphtory::{ algorithms::{ bipartite::max_weight_matching::max_weight_matching, diff --git a/raphtory-benchmark/src/algobench_common.rs b/raphtory-benchmark/src/algobench_common.rs index 770eda2a9d..df30ff878b 100644 --- a/raphtory-benchmark/src/algobench_common.rs +++ b/raphtory-benchmark/src/algobench_common.rs @@ -1,19 +1,3 @@ -#![allow(dead_code)] - -// Shared infrastructure for the algobench_* benchmark binaries (see benches/algobench_*.rs). -// -// Benchmarks are split across binaries by algorithm speed/complexity (fast / medium / slow) -// so that a run of the fast or medium tier isn't held hostage by a handful of expensive -// algorithms, and so slow algorithms can run against a smaller graph to keep wall-clock time -// reasonable. Only `algobench_views` benchmarks the graph/subgraph/layered/filtered view -// variants (on a representative algorithm from each speed tier); every other binary only -// benchmarks the plain graph. -// -// The underlying random_attachment graphs are expensive to build, so each variant -// (plain / weighted / typed, large / tiny) is constructed once per process and cached; -// every benchmark reuses the cached graph (cheap `Arc` clone) and only builds a cheap view -// (subgraph/filter/layer) on top of it. - use criterion::{Criterion, SamplingMode}; use raphtory::{ db::{ @@ -28,7 +12,7 @@ use raphtory::{ graphgen::random_attachment::random_attachment, prelude::*, }; -use std::{hint::black_box, sync::OnceLock}; +use std::sync::OnceLock; pub fn graph_benchmark_with_setup( c: &mut Criterion, @@ -53,8 +37,7 @@ pub fn graph_benchmark_with_setup( group.sample_size(sample_size); group.bench_function(name, |b| { b.iter(|| { - let result = run(&graph, &setup_data); - black_box(result); + run(&graph, &setup_data); }); }); group.finish(); @@ -83,28 +66,6 @@ pub fn graph_benchmark( ) } -pub fn simple_benchmark( - c: &mut Criterion, - name: &str, - measurement_secs: u64, - sample_size: usize, - mut run: Run, -) where - Run: FnMut() -> Output, -{ - let mut group = c.benchmark_group(name); - group.sampling_mode(SamplingMode::Flat); - group.measurement_time(std::time::Duration::from_secs(measurement_secs)); - group.sample_size(sample_size); - group.bench_function(name, |b| { - b.iter(|| { - let result = run(); - black_box(result); - }); - }); - group.finish() -} - pub fn first_node_id(graph: &G) -> GID { graph .nodes() @@ -114,8 +75,7 @@ pub fn first_node_id(graph: &G) -> GID { .expect("graph has nodes") } -// Large graph (5000 nodes) - used by the fast/medium tiers and as the base for the -// representative fast/medium/trivial algorithms in algobench_views. +// graph constructors pub fn build_large_random_attachment_graph() -> Graph { let graph = Graph::new(); @@ -137,7 +97,7 @@ pub fn large_random_attachment_subgraph() -> NodeSubgraph { pub fn large_random_attachment_filtered() -> impl StaticGraphViewOps { large_random_attachment_graph() - .filter(NodeFilter.degree().ge(0u64)) + .filter(NodeFilter.degree().ge(1u64)) .unwrap() } @@ -182,10 +142,6 @@ pub fn large_typed_random_attachment_graph() -> Graph { .clone() } -// Medium graph (1500 nodes) - dedicated to algobench_medium, distinct from the large -// (5000 node) graph so that binary isn't just running the fast/slow tiers' graph at a -// different set of algorithms. - pub fn build_medium_random_attachment_graph() -> Graph { let graph = Graph::new(); let seed: [u8; 32] = [1; 32]; @@ -253,9 +209,6 @@ pub fn medium_typed_random_attachment_graph() -> Graph { .clone() } -// Tiny graph (100 nodes) - dedicated to algorithms too expensive to run at the large -// graph's 5000-node scale (components, betweenness, temporal rich club, matching, layout). - pub fn build_tiny_random_attachment_graph() -> Graph { let graph = Graph::new(); let seed: [u8; 32] = [1; 32]; From 973b30ee1ae5b0a2242466ab948faf5fb370d909 Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Thu, 6 Aug 2026 08:55:24 -0500 Subject: [PATCH 23/24] fmt --- raphtory-benchmark/benches/algobench_fast.rs | 14 ++++++-------- raphtory-benchmark/benches/algobench_medium.rs | 7 +++++-- raphtory-benchmark/benches/algobench_slow.rs | 2 +- raphtory-benchmark/src/algobench_common.rs | 8 ++++++-- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/raphtory-benchmark/benches/algobench_fast.rs b/raphtory-benchmark/benches/algobench_fast.rs index 5058434ab4..93e7fb033b 100644 --- a/raphtory-benchmark/benches/algobench_fast.rs +++ b/raphtory-benchmark/benches/algobench_fast.rs @@ -1,7 +1,11 @@ +use criterion::{criterion_group, criterion_main, Criterion}; +use rand::{rngs::SmallRng, SeedableRng}; use raphtory::{ algorithms::{ centrality::degree_centrality::degree_centrality, + components::weakly_connected_components, components::{out_component, out_component_filtered}, + dynamics::temporal::epidemics::{temporal_SEIR, Number}, metrics::{ clustering_coefficient::{ local_clustering_coefficient::local_clustering_coefficient, @@ -13,22 +17,16 @@ use raphtory::{ }, directed_graph_density::directed_graph_density, }, - motifs::{ - local_triangle_count::local_triangle_count - }, + motifs::local_triangle_count::local_triangle_count, pathing::temporal_reachability::temporally_reachable_nodes, - components::weakly_connected_components, - dynamics::temporal::epidemics::{temporal_SEIR, Number}, }, db::graph::views::filter::Unfiltered, prelude::*, }; -use criterion::{criterion_group, criterion_main, Criterion}; -use rand::{rngs::SmallRng, SeedableRng}; use raphtory_benchmark::algobench_common::{ first_node_id, graph_benchmark, graph_benchmark_with_setup, large_random_attachment_filtered, large_random_attachment_graph, large_random_attachment_layered, - large_random_attachment_subgraph + large_random_attachment_subgraph, }; pub fn local_triangle_count_analysis(c: &mut Criterion) { diff --git a/raphtory-benchmark/benches/algobench_medium.rs b/raphtory-benchmark/benches/algobench_medium.rs index 7ea6974ce2..1e5b930001 100644 --- a/raphtory-benchmark/benches/algobench_medium.rs +++ b/raphtory-benchmark/benches/algobench_medium.rs @@ -1,3 +1,4 @@ +use criterion::{criterion_group, criterion_main, Criterion}; use raphtory::{ algorithms::{ centrality::{hits::hits, pagerank::page_rank}, @@ -33,10 +34,12 @@ use raphtory::{ db::graph::views::filter::Unfiltered, prelude::*, }; -use criterion::{criterion_group, criterion_main, Criterion}; use raphtory_api::core::Direction; use raphtory_benchmark::algobench_common::{ - first_node_id, graph_benchmark, graph_benchmark_with_setup, medium_random_attachment_filtered, medium_random_attachment_graph, medium_random_attachment_layered, medium_random_attachment_subgraph, medium_typed_random_attachment_graph, medium_weighted_random_attachment_graph, + first_node_id, graph_benchmark, graph_benchmark_with_setup, medium_random_attachment_filtered, + medium_random_attachment_graph, medium_random_attachment_layered, + medium_random_attachment_subgraph, medium_typed_random_attachment_graph, + medium_weighted_random_attachment_graph, }; pub fn graphgen_clustering_coeff(c: &mut Criterion) { diff --git a/raphtory-benchmark/benches/algobench_slow.rs b/raphtory-benchmark/benches/algobench_slow.rs index 22f1bbacd7..fd79f18bef 100644 --- a/raphtory-benchmark/benches/algobench_slow.rs +++ b/raphtory-benchmark/benches/algobench_slow.rs @@ -1,3 +1,4 @@ +use criterion::{criterion_group, criterion_main, Criterion}; use raphtory::{ algorithms::{ bipartite::max_weight_matching::max_weight_matching, @@ -14,7 +15,6 @@ use raphtory::{ db::graph::views::filter::Unfiltered, prelude::*, }; -use criterion::{criterion_group, criterion_main, Criterion}; use raphtory_benchmark::algobench_common::{ graph_benchmark, tiny_random_attachment_filtered, tiny_random_attachment_graph, tiny_random_attachment_layered, tiny_random_attachment_subgraph, diff --git a/raphtory-benchmark/src/algobench_common.rs b/raphtory-benchmark/src/algobench_common.rs index df30ff878b..f0b782952a 100644 --- a/raphtory-benchmark/src/algobench_common.rs +++ b/raphtory-benchmark/src/algobench_common.rs @@ -86,7 +86,9 @@ pub fn build_large_random_attachment_graph() -> Graph { pub fn large_random_attachment_graph() -> Graph { static GRAPH: OnceLock = OnceLock::new(); - GRAPH.get_or_init(build_large_random_attachment_graph).clone() + GRAPH + .get_or_init(build_large_random_attachment_graph) + .clone() } pub fn large_random_attachment_subgraph() -> NodeSubgraph { @@ -218,7 +220,9 @@ pub fn build_tiny_random_attachment_graph() -> Graph { pub fn tiny_random_attachment_graph() -> Graph { static GRAPH: OnceLock = OnceLock::new(); - GRAPH.get_or_init(build_tiny_random_attachment_graph).clone() + GRAPH + .get_or_init(build_tiny_random_attachment_graph) + .clone() } pub fn tiny_random_attachment_subgraph() -> NodeSubgraph { From c3145ecb91076eb9db5003b797b1bd1257f40a78 Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Thu, 6 Aug 2026 10:23:52 -0500 Subject: [PATCH 24/24] change measurement sec to 5 for each algo benchmark --- raphtory-benchmark/benches/algobench_fast.rs | 36 +++++++++---------- .../benches/algobench_medium.rs | 30 ++++++++-------- raphtory-benchmark/benches/algobench_slow.rs | 24 ++++++------- 3 files changed, 45 insertions(+), 45 deletions(-) diff --git a/raphtory-benchmark/benches/algobench_fast.rs b/raphtory-benchmark/benches/algobench_fast.rs index 93e7fb033b..dd63b2ace8 100644 --- a/raphtory-benchmark/benches/algobench_fast.rs +++ b/raphtory-benchmark/benches/algobench_fast.rs @@ -33,7 +33,7 @@ pub fn local_triangle_count_analysis(c: &mut Criterion) { graph_benchmark_with_setup( c, "local_triangle_count", - 3, + 5, 10, large_random_attachment_graph, first_node_id, @@ -45,7 +45,7 @@ pub fn local_clustering_coefficient_analysis(c: &mut Criterion) { graph_benchmark_with_setup( c, "local_clustering_coefficient", - 3, + 5, 10, large_random_attachment_graph, first_node_id, @@ -57,7 +57,7 @@ pub fn graphgen_directed_density(c: &mut Criterion) { graph_benchmark( c, "graphgen_directed_density", - 2, + 5, 10, large_random_attachment_graph, |graph, _| directed_graph_density(graph), @@ -65,7 +65,7 @@ pub fn graphgen_directed_density(c: &mut Criterion) { graph_benchmark( c, "graphgen_directed_density_subgraph", - 3, + 5, 10, large_random_attachment_subgraph, |graph, _| directed_graph_density(graph), @@ -73,7 +73,7 @@ pub fn graphgen_directed_density(c: &mut Criterion) { graph_benchmark( c, "graphgen_directed_density_layered", - 3, + 5, 10, large_random_attachment_layered, |graph, _| directed_graph_density(graph), @@ -92,7 +92,7 @@ pub fn graphgen_degree_centrality(c: &mut Criterion) { graph_benchmark( c, "graphgen_degree_centrality", - 3, + 5, 10, large_random_attachment_graph, |graph, _| degree_centrality(graph), @@ -114,7 +114,7 @@ pub fn graphgen_max_degree(c: &mut Criterion) { graph_benchmark( c, "graphgen_max_degree", - 3, + 5, 10, large_random_attachment_graph, |graph, _| max_degree(graph), @@ -125,7 +125,7 @@ pub fn graphgen_min_degree(c: &mut Criterion) { graph_benchmark( c, "graphgen_min_degree", - 3, + 5, 10, large_random_attachment_graph, |graph, _| min_degree(graph), @@ -136,7 +136,7 @@ pub fn graphgen_max_out_degree(c: &mut Criterion) { graph_benchmark( c, "graphgen_max_out_degree", - 3, + 5, 10, large_random_attachment_graph, |graph, _| max_out_degree(graph), @@ -147,7 +147,7 @@ pub fn graphgen_max_in_degree(c: &mut Criterion) { graph_benchmark( c, "graphgen_max_in_degree", - 3, + 5, 10, large_random_attachment_graph, |graph, _| max_in_degree(graph), @@ -158,7 +158,7 @@ pub fn graphgen_min_out_degree(c: &mut Criterion) { graph_benchmark( c, "graphgen_min_out_degree", - 3, + 5, 10, large_random_attachment_graph, |graph, _| min_out_degree(graph), @@ -169,7 +169,7 @@ pub fn graphgen_min_in_degree(c: &mut Criterion) { graph_benchmark( c, "graphgen_min_in_degree", - 3, + 5, 10, large_random_attachment_graph, |graph, _| min_in_degree(graph), @@ -180,7 +180,7 @@ pub fn graphgen_average_degree(c: &mut Criterion) { graph_benchmark( c, "graphgen_average_degree", - 3, + 5, 10, large_random_attachment_graph, |graph, _| average_degree(graph), @@ -191,7 +191,7 @@ pub fn graphgen_local_clustering_coefficient_batch(c: &mut Criterion) { graph_benchmark_with_setup( c, "graphgen_local_clustering_coefficient_batch", - 3, + 5, 10, large_random_attachment_graph, first_node_id, @@ -203,7 +203,7 @@ pub fn graphgen_temporally_reachable_nodes(c: &mut Criterion) { graph_benchmark_with_setup( c, "graphgen_temporally_reachable_nodes", - 3, + 5, 10, large_random_attachment_graph, first_node_id, @@ -215,7 +215,7 @@ pub fn graphgen_out_component(c: &mut Criterion) { graph_benchmark_with_setup( c, "graphgen_out_component", - 3, + 5, 10, large_random_attachment_graph, first_node_id, @@ -230,7 +230,7 @@ pub fn graphgen_out_component_filtered(c: &mut Criterion) { graph_benchmark_with_setup( c, "graphgen_out_component_filtered", - 3, + 5, 10, large_random_attachment_graph, first_node_id, @@ -245,7 +245,7 @@ pub fn graphgen_temporal_seir(c: &mut Criterion) { graph_benchmark( c, "graphgen_temporal_seir", - 3, + 5, 10, large_random_attachment_graph, |graph, _| { diff --git a/raphtory-benchmark/benches/algobench_medium.rs b/raphtory-benchmark/benches/algobench_medium.rs index 1e5b930001..b66172b18d 100644 --- a/raphtory-benchmark/benches/algobench_medium.rs +++ b/raphtory-benchmark/benches/algobench_medium.rs @@ -46,7 +46,7 @@ pub fn graphgen_clustering_coeff(c: &mut Criterion) { graph_benchmark( c, "graphgen_clustering_coeff", - 10, + 5, 10, medium_random_attachment_graph, |graph, _| global_clustering_coefficient(graph), @@ -57,7 +57,7 @@ pub fn graphgen_pagerank(c: &mut Criterion) { graph_benchmark( c, "graphgen_pagerank", - 10, + 5, 10, medium_random_attachment_graph, |graph, _| page_rank(graph, None, Some(100), None, None, true, None), @@ -65,7 +65,7 @@ pub fn graphgen_pagerank(c: &mut Criterion) { graph_benchmark( c, "graphgen_pagerank_subgraph", - 10, + 5, 10, medium_random_attachment_subgraph, |graph, _| page_rank(graph, None, Some(100), None, None, true, None), @@ -73,7 +73,7 @@ pub fn graphgen_pagerank(c: &mut Criterion) { graph_benchmark( c, "graphgen_pagerank_layered", - 10, + 5, 10, medium_random_attachment_layered, |graph, _| page_rank(graph, None, Some(100), None, None, true, None), @@ -81,7 +81,7 @@ pub fn graphgen_pagerank(c: &mut Criterion) { graph_benchmark( c, "graphgen_pagerank_graph_filtered", - 20, + 5, 10, medium_random_attachment_filtered, |graph, _| page_rank(graph, None, Some(100), None, None, true, None), @@ -103,7 +103,7 @@ pub fn graphgen_triangle_count(c: &mut Criterion) { graph_benchmark( c, "graphgen_triangle_count", - 10, + 5, 10, medium_random_attachment_graph, |graph, _| triangle_count(graph, None), @@ -147,7 +147,7 @@ pub fn graphgen_label_propagation(c: &mut Criterion) { graph_benchmark( c, "graphgen_label_propagation", - 20, + 5, 10, medium_random_attachment_graph, |graph, _| label_propagation(graph, 20, Some([1; 32]), None), @@ -158,7 +158,7 @@ pub fn graphgen_louvain(c: &mut Criterion) { graph_benchmark( c, "graphgen_louvain", - 20, + 5, 10, medium_random_attachment_graph, |graph, _| louvain::(graph, 1.0, None, None, Some(42)), @@ -191,7 +191,7 @@ pub fn graphgen_temporal_motif_multi(c: &mut Criterion) { graph_benchmark( c, "graphgen_temporal_motif_multi", - 20, + 5, 10, medium_random_attachment_graph, |graph, _| temporal_three_node_motif_multi(graph, vec![100], None), @@ -202,7 +202,7 @@ pub fn graphgen_local_temporal_motif(c: &mut Criterion) { graph_benchmark( c, "graphgen_local_temporal_motif", - 20, + 5, 10, medium_random_attachment_graph, |graph, _| local_temporal_three_node_motif(graph, 100, None), @@ -276,7 +276,7 @@ pub fn graphgen_internal_global_triangle_motifs(c: &mut Criterion) { graph_benchmark( c, "graphgen_internal_global_triangle_motifs", - 10, + 5, 10, medium_random_attachment_graph, |graph, _| global_triangle_motifs_internal(graph, vec![100], None), @@ -287,7 +287,7 @@ pub fn graphgen_internal_local_triangle_motifs(c: &mut Criterion) { graph_benchmark( c, "graphgen_internal_local_triangle_motifs", - 10, + 5, 10, medium_random_attachment_graph, |graph, _| local_triangle_motifs_internal(graph, vec![100], None), @@ -320,7 +320,7 @@ pub fn graphgen_fast_rp(c: &mut Criterion) { graph_benchmark( c, "graphgen_fast_rp", - 10, + 5, 10, medium_random_attachment_graph, |graph, _| fast_rp(graph, 32, 0.5, vec![1.0, 1.0, 1.0], Some(1), None), @@ -331,7 +331,7 @@ pub fn graphgen_temporal_bipartite_projection(c: &mut Criterion) { graph_benchmark( c, "graphgen_temporal_bipartite_projection", - 20, + 5, 10, medium_typed_random_attachment_graph, |graph, _| temporal_bipartite_projection(graph, 1, "Right".to_string()), @@ -342,7 +342,7 @@ pub fn temporal_motifs(c: &mut Criterion) { graph_benchmark( c, "temporal_motifs", - 20, + 5, 10, medium_random_attachment_graph, |graph, _| global_temporal_three_node_motif(graph, 100, None), diff --git a/raphtory-benchmark/benches/algobench_slow.rs b/raphtory-benchmark/benches/algobench_slow.rs index fd79f18bef..4f17ad1d5d 100644 --- a/raphtory-benchmark/benches/algobench_slow.rs +++ b/raphtory-benchmark/benches/algobench_slow.rs @@ -24,7 +24,7 @@ pub fn graphgen_betweenness(c: &mut Criterion) { graph_benchmark( c, "graphgen_betweenness", - 20, + 5, 10, tiny_random_attachment_graph, |graph, _| betweenness_centrality(graph, None, false), @@ -32,7 +32,7 @@ pub fn graphgen_betweenness(c: &mut Criterion) { graph_benchmark( c, "graphgen_betweenness_subgraph", - 20, + 5, 10, tiny_random_attachment_subgraph, |graph, _| betweenness_centrality(graph, None, false), @@ -40,7 +40,7 @@ pub fn graphgen_betweenness(c: &mut Criterion) { graph_benchmark( c, "graphgen_betweenness_layered", - 20, + 5, 10, tiny_random_attachment_layered, |graph, _| betweenness_centrality(graph, None, false), @@ -48,7 +48,7 @@ pub fn graphgen_betweenness(c: &mut Criterion) { graph_benchmark( c, "graphgen_betweenness_graph_filtered", - 20, + 5, 10, tiny_random_attachment_filtered, |graph, _| betweenness_centrality(graph, None, false), @@ -59,7 +59,7 @@ pub fn graphgen_in_components(c: &mut Criterion) { graph_benchmark( c, "graphgen_in_components", - 20, + 5, 10, tiny_random_attachment_graph, |graph, _| in_components(graph, None), @@ -70,7 +70,7 @@ pub fn graphgen_out_components(c: &mut Criterion) { graph_benchmark( c, "graphgen_out_components", - 20, + 5, 10, tiny_random_attachment_graph, |graph, _| out_components(graph, None), @@ -81,7 +81,7 @@ pub fn graphgen_in_components_filtered(c: &mut Criterion) { graph_benchmark( c, "graphgen_in_components_filtered", - 20, + 5, 10, tiny_random_attachment_graph, |graph, _| in_components_filtered(graph, None, Unfiltered).unwrap(), @@ -92,7 +92,7 @@ pub fn graphgen_out_components_filtered(c: &mut Criterion) { graph_benchmark( c, "graphgen_out_components_filtered", - 20, + 5, 10, tiny_random_attachment_graph, |graph, _| out_components_filtered(graph, None, Unfiltered).unwrap(), @@ -103,7 +103,7 @@ pub fn graphgen_temporal_rich_club(c: &mut Criterion) { graph_benchmark( c, "graphgen_temporal_rich_club", - 20, + 5, 10, tiny_random_attachment_graph, |graph, _| { @@ -117,7 +117,7 @@ pub fn graphgen_fruchterman_reingold(c: &mut Criterion) { graph_benchmark( c, "graphgen_fruchterman_reingold", - 20, + 5, 10, tiny_random_attachment_graph, |graph, _| fruchterman_reingold_unbounded(graph, 5, 1.0, 1.0, 0.9, 0.1), @@ -128,7 +128,7 @@ pub fn graphgen_cohesive_fruchterman_reingold(c: &mut Criterion) { graph_benchmark( c, "graphgen_cohesive_fruchterman_reingold", - 20, + 5, 10, tiny_random_attachment_graph, |graph, _| cohesive_fruchterman_reingold(graph, 5, 1.0, 1.0, 0.9, 0.1), @@ -139,7 +139,7 @@ pub fn graphgen_max_weight_matching(c: &mut Criterion) { graph_benchmark( c, "graphgen_max_weight_matching", - 20, + 5, 10, tiny_random_attachment_graph, |graph, _| max_weight_matching(graph, None, false, false),