Skip to content

Commit

Permalink
refactor(benches): improve parity of benchmark outputs (#288)
Browse files Browse the repository at this point in the history
* add prints to the shift benchmark

* correct bench name
  • Loading branch information
imrn99 authored Feb 17, 2025
1 parent 27df120 commit c6e6f85
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 16 deletions.
2 changes: 1 addition & 1 deletion benches/src/cut_edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub fn bench_cut_edges<T: CoordsFloat>(args: CutEdgesArgs) -> CMap2<T> {
"Input mesh isn't a triangle mesh"
);
}
println!("Run information");
println!("| cut-edges benchmark");
println!("|-> input : {input_map} (hash: {input_hash:#0x})",);
println!(
"|-> backend : {:?} with {n_threads} thread(s)",
Expand Down
72 changes: 57 additions & 15 deletions benches/src/shift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,26 @@
use rayon::prelude::*;

use honeycomb::core::stm::atomically;
use honeycomb::core::stm::{Transaction, TransactionControl};
use honeycomb::prelude::{
CMap2, CMapBuilder, CoordsFloat, DartIdType, Orbit2, OrbitPolicy, Vertex2, VertexIdType,
NULL_DART_ID,
};

use crate::cli::ShiftArgs;
use crate::utils::hash_file;

pub fn bench_shift<T: CoordsFloat>(args: ShiftArgs) -> CMap2<T> {
let map: CMap2<T> = CMapBuilder::from(args.input).build().unwrap();
let mut instant = std::time::Instant::now();
let input_map = args.input.to_str().unwrap();
let input_hash = hash_file(input_map).unwrap();
let map: CMap2<T> = CMapBuilder::from(input_map).build().unwrap();
let build_time = instant.elapsed();

if args.no_conflict {
todo!("TODO: require a partitioning algorithm")
} else {
instant = std::time::Instant::now();
// fetch all vertices that are not on the boundary of the map
let tmp: Vec<(VertexIdType, Vec<VertexIdType>)> = map
.iter_vertices()
Expand All @@ -49,22 +55,58 @@ pub fn bench_shift<T: CoordsFloat>(args: ShiftArgs) -> CMap2<T> {
}
})
.collect();
let n_v = tmp.len();
let graph_time = instant.elapsed();
let n_threads = std::thread::available_parallelism()
.map(|v| v.get())
.unwrap_or(1);

println!("| shift benchmark");
println!("|-> input : {input_map} (hash: {input_hash:#0x})");
println!("|-> backend : rayon-iter with {n_threads} thread(s)",);
println!("|-> # of rounds: {}", args.n_rounds.get());
println!("|-+ init time :");
println!("| |-> map built in {}ms", build_time.as_millis());
println!("| |-> graph built in {}ms", graph_time.as_millis());

println!(" Round | process_time | throughput(vertex/s) | n_transac_retry");
// main loop
let mut round = 0;
let mut process_time;
loop {
tmp.par_iter().for_each(|(vid, neigh)| {
atomically(|trans| {
let mut new_val = Vertex2::default();
for v in neigh {
let vertex = map.read_vertex(trans, *v)?.unwrap();
new_val.0 += vertex.0;
new_val.1 += vertex.1;
}
new_val.0 /= T::from(neigh.len()).unwrap();
new_val.1 /= T::from(neigh.len()).unwrap();
map.write_vertex(trans, *vid, new_val)
});
});
instant = std::time::Instant::now();
let n_retry: u32 = tmp
.par_iter()
.map(|(vid, neigh)| {
let mut n = 0;
Transaction::with_control(
|_| {
n += 1;
TransactionControl::Retry
},
|trans| {
let mut new_val = Vertex2::default();
for v in neigh {
let vertex = map.read_vertex(trans, *v)?.unwrap();
new_val.0 += vertex.0;
new_val.1 += vertex.1;
}
new_val.0 /= T::from(neigh.len()).unwrap();
new_val.1 /= T::from(neigh.len()).unwrap();
map.write_vertex(trans, *vid, new_val)
},
); // Transaction::with_control
n
})
.sum();
process_time = instant.elapsed().as_secs_f64();
println!(
" {:>5} | {:>12.6e} | {:>20.6e} | {:>15}",
round,
process_time,
n_v as f64 / process_time,
n_retry,
);

round += 1;
if round >= args.n_rounds.get() {
Expand Down

0 comments on commit c6e6f85

Please sign in to comment.