mod datagen;
use criterion::{BenchmarkId, Criterion, black_box, criterion_group, criterion_main};
use rsigma_parser::parse_sigma_yaml;
fn bench_parse_single_rule(c: &mut Criterion) {
let yaml = datagen::gen_n_rules(1);
c.bench_function("parse_single_rule", |b| {
b.iter(|| {
let result = parse_sigma_yaml(black_box(&yaml)).unwrap();
black_box(result);
});
});
}
fn bench_parse_scaling(c: &mut Criterion) {
let mut group = c.benchmark_group("parse_rules");
for n in [10, 100, 500, 1000] {
let yaml = datagen::gen_n_rules(n);
let yaml_len = yaml.len();
group.bench_with_input(BenchmarkId::new("count", n), &yaml, |b, yaml| {
b.iter(|| {
let result = parse_sigma_yaml(black_box(yaml)).unwrap();
black_box(result);
});
});
group.throughput(criterion::Throughput::Bytes(yaml_len as u64));
}
group.finish();
}
fn bench_parse_complex_condition(c: &mut Criterion) {
let yaml = datagen::gen_complex_condition_rule();
c.bench_function("parse_complex_condition", |b| {
b.iter(|| {
let result = parse_sigma_yaml(black_box(&yaml)).unwrap();
black_box(result);
});
});
}
fn bench_parse_wildcard_rules(c: &mut Criterion) {
let mut group = c.benchmark_group("parse_wildcard_rules");
for n in [100, 500, 1000] {
let yaml = datagen::gen_n_wildcard_rules(n);
group.bench_with_input(BenchmarkId::new("count", n), &yaml, |b, yaml| {
b.iter(|| {
let result = parse_sigma_yaml(black_box(yaml)).unwrap();
black_box(result);
});
});
}
group.finish();
}
fn bench_parse_regex_rules(c: &mut Criterion) {
let mut group = c.benchmark_group("parse_regex_rules");
for n in [100, 500, 1000] {
let yaml = datagen::gen_n_regex_rules(n);
group.bench_with_input(BenchmarkId::new("count", n), &yaml, |b, yaml| {
b.iter(|| {
let result = parse_sigma_yaml(black_box(yaml)).unwrap();
black_box(result);
});
});
}
group.finish();
}
criterion_group!(
benches,
bench_parse_single_rule,
bench_parse_scaling,
bench_parse_complex_condition,
bench_parse_wildcard_rules,
bench_parse_regex_rules,
);
criterion_main!(benches);