From 500ed0801d145984e1d387c9138851f9ac2046c0 Mon Sep 17 00:00:00 2001 From: Daniel Lacina Date: Tue, 16 Jun 2026 14:07:27 -0500 Subject: [PATCH 01/11] 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/11] 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/11] 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/11] 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/11] 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/11] 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/11] 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/11] 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/11] 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/11] 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/11] 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 }