Skip to content

Commit

Permalink
Merge pull request #554 from JakeRoggenbuck/more-benchmarks
Browse files Browse the repository at this point in the history
Add more benchmarks
  • Loading branch information
JakeRoggenbuck authored Jan 23, 2024
2 parents ed557fc + 2297c91 commit cd84ee0
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ path = "src/bin/main.rs"
[[bench]]
name = "system_benchmark"
harness = false

[[bench]]
name = "graph_benchmark"
harness = false
41 changes: 41 additions & 0 deletions benches/graph_benchmark.rs
Original file line number Diff line number Diff line change
@@ -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);
1 change: 1 addition & 0 deletions benches/system_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ criterion_group!(
list_cpus_benchmark,
set_best_path_benchmark
);

criterion_main!(benches);

0 comments on commit cd84ee0

Please sign in to comment.