From 84579da4eedd9a8ae6f2f41ab23600506b7007ab Mon Sep 17 00:00:00 2001 From: oneofthezombies Date: Tue, 13 Feb 2024 01:30:27 +0900 Subject: [PATCH] chore: add bench --- .github/workflows/CI.yml | 6 ++-- crates/libs/kill_tree/benches/bench.rs | 38 ++++++++++++++++++++++++++ crates/tools/dev/src/main.rs | 24 ++++++++-------- 3 files changed, 54 insertions(+), 14 deletions(-) create mode 100644 crates/libs/kill_tree/benches/bench.rs diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index a9ff52d..092237e 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -38,11 +38,13 @@ jobs: run: cargo run --package tool-dev -- clippy - name: Format run: cargo run --package tool-dev -- fmt + - name: Test + run: cargo run --package tool-dev -- test + - name: Bench + run: cargo run --package tool-dev -- bench - name: Build id: build run: cargo run --package tool-dev -- build --target ${{ matrix.target }} - - name: Test - run: cargo run --package tool-dev -- test --target ${{ matrix.target }} - name: Upload Artifact uses: actions/upload-artifact@v4 with: diff --git a/crates/libs/kill_tree/benches/bench.rs b/crates/libs/kill_tree/benches/bench.rs new file mode 100644 index 0000000..7a05a1d --- /dev/null +++ b/crates/libs/kill_tree/benches/bench.rs @@ -0,0 +1,38 @@ +#![feature(test)] + +extern crate test; + +use kill_tree::{get_available_max_process_id, Config}; +use test::Bencher; + +#[bench] +fn kill_tree(b: &mut Bencher) { + b.iter(|| { + let target_process_id = get_available_max_process_id(); + kill_tree::blocking::kill_tree(target_process_id).unwrap(); + }); +} + +#[bench] +fn kill_tree_with_sigkill(b: &mut Bencher) { + b.iter(|| { + let target_process_id = get_available_max_process_id(); + let config = Config { + signal: String::from("SIGKILL"), + ..Default::default() + }; + kill_tree::blocking::kill_tree_with_config(target_process_id, &config).unwrap(); + }); +} + +#[bench] +fn kill_tree_exclude_target(b: &mut Bencher) { + b.iter(|| { + let target_process_id = get_available_max_process_id(); + let config = Config { + include_target: false, + ..Default::default() + }; + kill_tree::blocking::kill_tree_with_config(target_process_id, &config).unwrap(); + }); +} diff --git a/crates/tools/dev/src/main.rs b/crates/tools/dev/src/main.rs index be07926..2e6fadc 100644 --- a/crates/tools/dev/src/main.rs +++ b/crates/tools/dev/src/main.rs @@ -15,14 +15,12 @@ enum Command { Check, Clippy, Fmt, + Bench, + Test, Build { #[arg(short, long)] target: String, }, - Test { - #[arg(short, long)] - target: Option, - }, PrePush, } @@ -84,19 +82,20 @@ fn build(target: &str) { } } -fn test(target: Option) { - if let Some(target) = target { - run!("cargo test --target {target}"); - } else { - run!("cargo test --workspace"); - } +fn test() { + run!("cargo test --workspace --all-targets --all-features"); +} + +fn bench() { + run!("cargo bench --workspace --all-targets --all-features"); } fn pre_push() { check(); clippy(); fmt(); - test(None); + test(); + bench(); } fn init_log() { @@ -119,8 +118,9 @@ fn main() { Command::Check => check(), Command::Clippy => clippy(), Command::Fmt => fmt(), + Command::Bench => bench(), + Command::Test => test(), Command::Build { target } => build(&target), - Command::Test { target } => test(target), Command::PrePush => pre_push(), } }