Skip to content

Commit c0916c9

Browse files
committed
Add bench for Pwsh
1 parent 8d3eb25 commit c0916c9

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

Cargo.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@ harness = false
3434
required-features = ["bash"]
3535

3636
[[bench]]
37-
name = "sh"
37+
name = "fish"
3838
harness = false
39-
required-features = ["sh"]
39+
required-features = ["fish"]
4040

4141
[[bench]]
42-
name = "fish"
42+
name = "pwsh"
4343
harness = false
44-
required-features = ["fish"]
44+
required-features = ["pwsh"]
45+
46+
[[bench]]
47+
name = "sh"
48+
harness = false
49+
required-features = ["sh"]

benches/pwsh.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use criterion::{black_box, criterion_group, criterion_main, Criterion};
2+
3+
use shell_quote::Pwsh;
4+
5+
fn criterion_benchmark(c: &mut Criterion) {
6+
let empty_string = "";
7+
c.bench_function("pwsh escape empty", |b| {
8+
b.iter(|| Pwsh::quote_vec(black_box(empty_string)))
9+
});
10+
11+
let alphanumeric_short = "abcdefghijklmnopqrstuvwxyz0123456789";
12+
c.bench_function("pwsh escape a-z", |b| {
13+
b.iter(|| Pwsh::quote_vec(black_box(alphanumeric_short)))
14+
});
15+
16+
let alphanumeric_long = alphanumeric_short.repeat(1000);
17+
c.bench_function("pwsh escape a-z long", |b| {
18+
b.iter(|| Pwsh::quote_vec(black_box(&alphanumeric_long)))
19+
});
20+
21+
let bytes_short = (1..=255u8).map(char::from).collect::<String>();
22+
c.bench_function("pwsh escape bytes", |b| {
23+
b.iter(|| Pwsh::quote_vec(black_box(&bytes_short)))
24+
});
25+
26+
let bytes_long = bytes_short.repeat(1000);
27+
c.bench_function("pwsh escape bytes long", |b| {
28+
b.iter(|| Pwsh::quote_vec(black_box(&bytes_long)))
29+
});
30+
31+
let utf8 = ('\x01'..=char::MAX).collect::<String>();
32+
c.bench_function("pwsh escape utf-8", |b| {
33+
b.iter(|| Pwsh::quote_vec(black_box(&utf8)))
34+
});
35+
}
36+
37+
criterion_group!(benches, criterion_benchmark);
38+
criterion_main!(benches);

0 commit comments

Comments
 (0)