Skip to content

Commit 84579da

Browse files
committed
chore: add bench
1 parent 9f59c16 commit 84579da

File tree

3 files changed

+54
-14
lines changed

3 files changed

+54
-14
lines changed

.github/workflows/CI.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,13 @@ jobs:
3838
run: cargo run --package tool-dev -- clippy
3939
- name: Format
4040
run: cargo run --package tool-dev -- fmt
41+
- name: Test
42+
run: cargo run --package tool-dev -- test
43+
- name: Bench
44+
run: cargo run --package tool-dev -- bench
4145
- name: Build
4246
id: build
4347
run: cargo run --package tool-dev -- build --target ${{ matrix.target }}
44-
- name: Test
45-
run: cargo run --package tool-dev -- test --target ${{ matrix.target }}
4648
- name: Upload Artifact
4749
uses: actions/upload-artifact@v4
4850
with:
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#![feature(test)]
2+
3+
extern crate test;
4+
5+
use kill_tree::{get_available_max_process_id, Config};
6+
use test::Bencher;
7+
8+
#[bench]
9+
fn kill_tree(b: &mut Bencher) {
10+
b.iter(|| {
11+
let target_process_id = get_available_max_process_id();
12+
kill_tree::blocking::kill_tree(target_process_id).unwrap();
13+
});
14+
}
15+
16+
#[bench]
17+
fn kill_tree_with_sigkill(b: &mut Bencher) {
18+
b.iter(|| {
19+
let target_process_id = get_available_max_process_id();
20+
let config = Config {
21+
signal: String::from("SIGKILL"),
22+
..Default::default()
23+
};
24+
kill_tree::blocking::kill_tree_with_config(target_process_id, &config).unwrap();
25+
});
26+
}
27+
28+
#[bench]
29+
fn kill_tree_exclude_target(b: &mut Bencher) {
30+
b.iter(|| {
31+
let target_process_id = get_available_max_process_id();
32+
let config = Config {
33+
include_target: false,
34+
..Default::default()
35+
};
36+
kill_tree::blocking::kill_tree_with_config(target_process_id, &config).unwrap();
37+
});
38+
}

crates/tools/dev/src/main.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ enum Command {
1515
Check,
1616
Clippy,
1717
Fmt,
18+
Bench,
19+
Test,
1820
Build {
1921
#[arg(short, long)]
2022
target: String,
2123
},
22-
Test {
23-
#[arg(short, long)]
24-
target: Option<String>,
25-
},
2624
PrePush,
2725
}
2826

@@ -84,19 +82,20 @@ fn build(target: &str) {
8482
}
8583
}
8684

87-
fn test(target: Option<String>) {
88-
if let Some(target) = target {
89-
run!("cargo test --target {target}");
90-
} else {
91-
run!("cargo test --workspace");
92-
}
85+
fn test() {
86+
run!("cargo test --workspace --all-targets --all-features");
87+
}
88+
89+
fn bench() {
90+
run!("cargo bench --workspace --all-targets --all-features");
9391
}
9492

9593
fn pre_push() {
9694
check();
9795
clippy();
9896
fmt();
99-
test(None);
97+
test();
98+
bench();
10099
}
101100

102101
fn init_log() {
@@ -119,8 +118,9 @@ fn main() {
119118
Command::Check => check(),
120119
Command::Clippy => clippy(),
121120
Command::Fmt => fmt(),
121+
Command::Bench => bench(),
122+
Command::Test => test(),
122123
Command::Build { target } => build(&target),
123-
Command::Test { target } => test(target),
124124
Command::PrePush => pre_push(),
125125
}
126126
}

0 commit comments

Comments
 (0)