From 6de6d2abb9bb101023fbd32972dce06f2f0c8d43 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sat, 3 Jul 2021 13:11:58 +0000 Subject: test(whirl_common): add criterion benchmarks --- benches/whirl_common.rs | 15 --------------- benches/whirl_common_criterion.rs | 23 +++++++++++++++++++++++ benches/whirl_common_iai.rs | 15 +++++++++++++++ crates/whirl_common/Cargo.toml | 9 ++++++++- 4 files changed, 46 insertions(+), 16 deletions(-) delete mode 100644 benches/whirl_common.rs create mode 100644 benches/whirl_common_criterion.rs create mode 100644 benches/whirl_common_iai.rs diff --git a/benches/whirl_common.rs b/benches/whirl_common.rs deleted file mode 100644 index 025c719..0000000 --- a/benches/whirl_common.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (C) 2021-2021 The Whirlsplash Collective -// SPDX-License-Identifier: GPL-3.0-only - -fn iai_benchmark_sort_vec_alphabetically() { - whirl_common::sort::vec_alphabetically(&mut vec!["a", "c", "d", "b"]) -} - -fn iai_benchmark_system_seconds_to_hrtime() -> String { - whirl_common::system::seconds_to_hrtime(1623058677) -} - -iai::main!( - iai_benchmark_sort_vec_alphabetically, - iai_benchmark_system_seconds_to_hrtime -); 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_iai.rs b/benches/whirl_common_iai.rs new file mode 100644 index 0000000..025c719 --- /dev/null +++ b/benches/whirl_common_iai.rs @@ -0,0 +1,15 @@ +// Copyright (C) 2021-2021 The Whirlsplash Collective +// SPDX-License-Identifier: GPL-3.0-only + +fn iai_benchmark_sort_vec_alphabetically() { + whirl_common::sort::vec_alphabetically(&mut vec!["a", "c", "d", "b"]) +} + +fn iai_benchmark_system_seconds_to_hrtime() -> String { + whirl_common::system::seconds_to_hrtime(1623058677) +} + +iai::main!( + iai_benchmark_sort_vec_alphabetically, + iai_benchmark_system_seconds_to_hrtime +); 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 -- cgit v1.2.3