|
| 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