Skip to content

Commit

Permalink
fix: fixed wildcard and string matching benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
pamburus committed Mar 1, 2024
1 parent 6abffc4 commit 09c16fb
Show file tree
Hide file tree
Showing 6 changed files with 273 additions and 81 deletions.
69 changes: 68 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ categories = ["command-line-utilities"]
description = "Utility for viewing json-formatted log files."
keywords = ["cli", "human", "log"]
name = "hl"
version = "0.25.3-alpha.5"
version = "0.25.3"
edition = "2021"
build = "build.rs"

Expand Down Expand Up @@ -71,6 +71,7 @@ criterion = "0"
stats_alloc = "0"
regex = "1"
wildmatch = "2"
wildflower = "0"

[profile.release]
debug = false
Expand All @@ -91,7 +92,11 @@ name = "ts-format"
harness = false

[[bench]]
name = "wildcard"
name = "wildmatch"
harness = false

[[bench]]
name = "wildflower"
harness = false

[[bench]]
Expand All @@ -102,6 +107,10 @@ harness = false
name = "parse-and-format"
harness = false

[[bench]]
name = "string"
harness = false

[[bench]]
name = "json"
harness = false
50 changes: 50 additions & 0 deletions benches/string.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// std imports
use std::alloc::System;

// third-party imports
use criterion::{criterion_group, criterion_main, Criterion};
use stats_alloc::{StatsAlloc, INSTRUMENTED_SYSTEM};
use std::hint::black_box;

#[global_allocator]
static GLOBAL: &StatsAlloc<System> = &INSTRUMENTED_SYSTEM;

fn benchmark(c: &mut Criterion) {
let mut c = c.benchmark_group("string");
let prefix = String::from("_");

c.bench_function("string-short-match", |b| {
let what = String::from("_TEST");
b.iter(|| {
assert_eq!(black_box(&what).starts_with(black_box(&prefix)), true);
});
});
c.bench_function("string-long-match", |b| {
let what = String::from("_TEST_SOME_VERY_VERY_LONG_NAME");
b.iter(|| {
assert_eq!(black_box(&what).starts_with(black_box(&prefix)), true);
});
});
c.bench_function("string-short-non-match", |b| {
let what = String::from("TEST");
b.iter(|| {
assert_eq!(black_box(&what).starts_with(black_box(&prefix)), false);
});
});
c.bench_function("string-long-non-match", |b| {
let what = String::from("TEST_SOME_VERY_VERY_LONG_NAME");
b.iter(|| {
assert_eq!(black_box(&what).starts_with(black_box(&prefix)), false);
});
});
c.bench_function("string-long-prefix-match", |b| {
let prefix = String::from("TEST_SOME_VERY_VERY_LONG_PREFIX_");
let what = String::from("TEST_SOME_VERY_VERY_LONG_PREFIX_AND_SOMEWHAT");
b.iter(|| {
assert_eq!(black_box(&what).starts_with(black_box(&prefix)), true);
});
});
}

criterion_group!(benches, benchmark);
criterion_main!(benches);
78 changes: 0 additions & 78 deletions benches/wildcard.rs

This file was deleted.

72 changes: 72 additions & 0 deletions benches/wildflower.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// std imports
use std::alloc::System;

// third-party imports
use criterion::{criterion_group, criterion_main, Criterion};
use stats_alloc::{Region, StatsAlloc, INSTRUMENTED_SYSTEM};
use std::hint::black_box;
use wildflower::Pattern;

#[global_allocator]
static GLOBAL: &StatsAlloc<System> = &INSTRUMENTED_SYSTEM;

fn benchmark(c: &mut Criterion) {
let mut c = c.benchmark_group("wildflower");
let pattern = Pattern::new(r"_*");

let mut c1 = None;
let mut n1 = 0;
c.bench_function("wildflower-short-match", |b| {
let what = "_TEST";
let reg = Region::new(&GLOBAL);
b.iter(|| {
assert_eq!(black_box(&pattern).matches(black_box(&what)), true);
n1 += 1;
});
c1 = Some(reg.change());
});
println!("allocations at 1 ({:?} iterations): {:#?}", n1, c1);

let mut c2 = None;
let mut n2 = 0;
c.bench_function("wildflower-long-match", |b| {
let what = "_TEST_SOME_VERY_VERY_LONG_NAME";
let reg = Region::new(&GLOBAL);
b.iter(|| {
assert_eq!(black_box(&pattern).matches(black_box(&what)), true);
n2 += 1;
});
c2 = Some(reg.change());
});
println!("allocations at 2 ({:?} iterations): {:#?}", n2, c2);

let mut c2 = None;
let mut n2 = 0;
c.bench_function("wildflower-long-prefix-match", |b| {
let pattern = Pattern::new(r"SOME_VERY_VERY_LONG_PREFIX_*");
let what = "SOME_VERY_VERY_LONG_PREFIX_AND_SOMEWHAT";
let reg = Region::new(&GLOBAL);
b.iter(|| {
assert_eq!(black_box(&pattern).matches(black_box(&what)), true);
n2 += 1;
});
c2 = Some(reg.change());
});
println!("allocations at 2 ({:?} iterations): {:#?}", n2, c2);

c.bench_function("wildflower-short-non-match", |b| {
let what = "TEST";
b.iter(|| {
assert_eq!(black_box(&pattern).matches(black_box(&what)), false);
});
});
c.bench_function("wildflower-long-non-match", |b| {
let what = "TEST_SOME_VERY_VERY_LONG_NAME";
b.iter(|| {
assert_eq!(black_box(&pattern).matches(black_box(&what)), false);
});
});
}

criterion_group!(benches, benchmark);
criterion_main!(benches);
Loading

0 comments on commit 09c16fb

Please sign in to comment.