diff options
| author | Fuwn <[email protected]> | 2021-07-03 13:11:58 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-07-03 13:11:58 +0000 |
| commit | 6de6d2abb9bb101023fbd32972dce06f2f0c8d43 (patch) | |
| tree | 0a243d3b7c6271223aa99a3b5ffc776f25f9b909 | |
| parent | style(crates): minor changes to crate descriptions (diff) | |
| download | whirl-6de6d2abb9bb101023fbd32972dce06f2f0c8d43.tar.xz whirl-6de6d2abb9bb101023fbd32972dce06f2f0c8d43.zip | |
test(whirl_common): add criterion benchmarks
| -rw-r--r-- | benches/whirl_common_criterion.rs | 23 | ||||
| -rw-r--r-- | benches/whirl_common_iai.rs (renamed from benches/whirl_common.rs) | 0 | ||||
| -rw-r--r-- | crates/whirl_common/Cargo.toml | 9 |
3 files changed, 31 insertions, 1 deletions
diff --git a/benches/whirl_common_criterion.rs b/benches/whirl_common_criterion.rs new file mode 100644 index 0000000..b004530 --- /dev/null +++ b/benches/whirl_common_criterion.rs @@ -0,0 +1,23 @@ +// Copyright (C) 2021-2021 The Whirlsplash Collective +// SPDX-License-Identifier: GPL-3.0-only + +use criterion::{criterion_group, criterion_main, Criterion}; + +fn criterion_benchmark_sort_vec_alphabetically(c: &mut Criterion) { + c.bench_function("sort vec alphabetically", |b| { + b.iter(|| whirl_common::sort::vec_alphabetically(&mut vec!["a", "c", "d", "b"])) + }); +} + +fn criterion_benchmark_system_seconds_to_hrtime(c: &mut Criterion) { + c.bench_function("system seconds to human readable time", |b| { + b.iter(|| whirl_common::system::seconds_to_hrtime(1623058677)) + }); +} + +criterion_group!( + benches, + criterion_benchmark_sort_vec_alphabetically, + criterion_benchmark_system_seconds_to_hrtime, +); +criterion_main!(benches); diff --git a/benches/whirl_common.rs b/benches/whirl_common_iai.rs index 025c719..025c719 100644 --- a/benches/whirl_common.rs +++ b/benches/whirl_common_iai.rs diff --git a/crates/whirl_common/Cargo.toml b/crates/whirl_common/Cargo.toml index f10348f..cf68756 100644 --- a/crates/whirl_common/Cargo.toml +++ b/crates/whirl_common/Cargo.toml @@ -17,9 +17,16 @@ publish = false whirl_config = { path = "../whirl_config" } [dev-dependencies] +# Benchmark iai = "0.1.1" +criterion = { version = "0.3.4", features = ["html_reports"] } [[bench]] name = "whirl_common" -path = "../../benches/whirl_common.rs" +path = "../../benches/whirl_common_iai.rs" +harness = false + +[[bench]] +name = "whirl_common_criterion" +path = "../../benches/whirl_common_criterion.rs" harness = false |