aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-07-03 13:11:58 +0000
committerFuwn <[email protected]>2021-07-03 13:11:58 +0000
commit6de6d2abb9bb101023fbd32972dce06f2f0c8d43 (patch)
tree0a243d3b7c6271223aa99a3b5ffc776f25f9b909
parentstyle(crates): minor changes to crate descriptions (diff)
downloadwhirl-6de6d2abb9bb101023fbd32972dce06f2f0c8d43.tar.xz
whirl-6de6d2abb9bb101023fbd32972dce06f2f0c8d43.zip
test(whirl_common): add criterion benchmarks
-rw-r--r--benches/whirl_common_criterion.rs23
-rw-r--r--benches/whirl_common_iai.rs (renamed from benches/whirl_common.rs)0
-rw-r--r--crates/whirl_common/Cargo.toml9
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