Skip to content

Commit

Permalink
chore: add bench
Browse files Browse the repository at this point in the history
  • Loading branch information
oneofthezombies committed Feb 12, 2024
1 parent 9f59c16 commit 84579da
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 14 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
38 changes: 38 additions & 0 deletions crates/libs/kill_tree/benches/bench.rs
Original file line number Diff line number Diff line change
@@ -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();
});
}
24 changes: 12 additions & 12 deletions crates/tools/dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ enum Command {
Check,
Clippy,
Fmt,
Bench,
Test,
Build {
#[arg(short, long)]
target: String,
},
Test {
#[arg(short, long)]
target: Option<String>,
},
PrePush,
}

Expand Down Expand Up @@ -84,19 +82,20 @@ fn build(target: &str) {
}
}

fn test(target: Option<String>) {
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() {
Expand All @@ -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(),
}
}

0 comments on commit 84579da

Please sign in to comment.