From 2297c91c2b3303a816be2a63a85d0950660427fd Mon Sep 17 00:00:00 2001 From: Jake Date: Mon, 22 Jan 2024 01:09:49 -0800 Subject: [PATCH] Add all benchmarks --- Cargo.lock | 2 +- Cargo.toml | 4 ++++ benches/graph_benchmark.rs | 41 +++++++++++++++++++++++++++++++++++++ benches/system_benchmark.rs | 1 + 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 benches/graph_benchmark.rs diff --git a/Cargo.lock b/Cargo.lock index 4f856c9..fa9e5e2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -68,7 +68,7 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "autoclockspeed" -version = "0.1.11" +version = "0.1.12" dependencies = [ "cached", "criterion", diff --git a/Cargo.toml b/Cargo.toml index 9485c6f..664d45c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,3 +38,7 @@ path = "src/bin/main.rs" [[bench]] name = "system_benchmark" harness = false + +[[bench]] +name = "graph_benchmark" +harness = false diff --git a/benches/graph_benchmark.rs b/benches/graph_benchmark.rs new file mode 100644 index 0000000..41e40e8 --- /dev/null +++ b/benches/graph_benchmark.rs @@ -0,0 +1,41 @@ +use autoclockspeed::graph::{Graph, Grapher}; +use criterion::{black_box, criterion_group, criterion_main, Criterion}; + +fn update_all_benchmark(c: &mut Criterion) { + let mut graph = Graph::new(); + let vec = vec![0.0; 100]; + graph.vals = vec; + c.bench_function("update_all", |b| b.iter(|| graph.update_all())); +} + +fn update_one_benchmark(c: &mut Criterion) { + let graph = Graph::new(); + let mut vec = vec![0.0; 100]; + c.bench_function("update_one", |b| { + b.iter(|| black_box(graph.update_one(&mut vec))) + }); +} + +fn clear_before_benchmark(c: &mut Criterion) { + let graph = Graph::new(); + let mut vec = vec![0.0; 100]; + c.bench_function("clear_before", |b| { + b.iter(|| black_box(graph.clear_before(&mut vec))) + }); +} + +fn plot_benchmark(c: &mut Criterion) { + let graph = Graph::new(); + let nums = vec![0.0; 100]; + c.bench_function("plot", |b| b.iter(|| black_box(graph.plot(nums.clone())))); +} + +criterion_group!( + benches, + update_all_benchmark, + update_one_benchmark, + clear_before_benchmark, + plot_benchmark +); + +criterion_main!(benches); diff --git a/benches/system_benchmark.rs b/benches/system_benchmark.rs index e39c163..c5d256f 100644 --- a/benches/system_benchmark.rs +++ b/benches/system_benchmark.rs @@ -26,4 +26,5 @@ criterion_group!( list_cpus_benchmark, set_best_path_benchmark ); + criterion_main!(benches);