Author SHA1 Message Date
Sylvestre Ledru b46a86d48a bench: end-to-end search throughput via uumain
The existing match/throughput benches call Matcher::match_line on
pre-split lines, so they only measure matching in isolation and cannot
observe how the searcher feeds data to the matcher. Add a 'search'
group that drives the whole pipeline through uumain over a multi-MB
file: a literal pattern (which a buffer-at-a-time searcher can speed
up) and an extended-regex control (which it cannot). Uses -q with a
non-matching pattern for a silent full-file scan.
2026-05-31 10:41:52 +02:00
Sylvestre LedruandGitHub b0164440e3 Merge pull request #14 from uutils/fix
Add Default impl for GlobSet to satisfy clippy
2026-05-31 10:34:25 +02:00
Sylvestre Ledru 96762f26ca Add Default impl for GlobSet to satisfy clippy 2026-05-31 10:18:32 +02:00
Sylvestre Ledru c8dfef6563 Add pre-commit configuration 2026-05-31 10:11:57 +02:00
Sylvestre LedruandGitHub ddac723054 Merge pull request #13 from uutils/codspeed-wizard-1780213675759
Add CodSpeed performance benchmarks
2026-05-31 10:11:23 +02:00
4 changed files with 134 additions and 1 deletions
+55
View File
@@ -0,0 +1,55 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
exclude: ^tests/fixtures/
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v6.0.0
hooks:
- id: check-added-large-files
- id: check-executables-have-shebangs
- id: check-json
exclude: '\.vscode/(cSpell|extensions)\.json' # cSpell.json and extensions.json use comments
- id: check-shebang-scripts-are-executable
exclude: '.+\.rs' # would be triggered by #![some_attribute]
- id: check-symlinks
- id: check-toml
- id: check-yaml
args: [ --allow-multiple-documents ]
- id: destroyed-symlinks
- id: end-of-file-fixer
- id: mixed-line-ending
args: [ --fix=lf ]
- id: trailing-whitespace
- repo: local
hooks:
- id: rust-linting
name: Rust linting
description: Run cargo fmt on files included in the commit.
entry: cargo +stable fmt --
pass_filenames: true
types: [file, rust]
language: system
- id: rust-clippy
name: Rust clippy
description: Run cargo clippy on files included in the commit.
entry: cargo +stable clippy --workspace --all-targets --all-features -- -D warnings
pass_filenames: false
types: [file, rust]
language: system
- id: cargo-lock-check
name: Cargo.lock sync check
description: Ensure Cargo.lock and fuzz/Cargo.lock are up-to-date.
entry: bash -c 'for dir in . fuzz; do if [ -d "$dir" ]; then ( cd "$dir" && cargo fetch --quiet ); fi; done'
pass_filenames: false
files: 'Cargo\.(toml|lock)$'
language: system
- id: cspell
name: Code spell checker (cspell)
description: Run cspell to check for spelling errors (if available).
entry: bash -c 'if command -v cspell >/dev/null 2>&1; then cspell --no-must-find-files -- "$@"; else echo "cspell not found, skipping spell check"; exit 0; fi' --
pass_filenames: true
language: system
ci:
skip: [rust-linting, rust-clippy, cargo-lock-check, cspell]
+4
View File
@@ -30,6 +30,10 @@ cargo build --release
cargo test
```
## Pre-commit hooks
This project uses [pre-commit](https://pre-commit.com); run `pre-commit install` to enable the git hooks.
## Known Issues
* Does not take `LANG`, etc., into account for handling file encodings (non-UTF8 matches are treated as binary)
+69 -1
View File
@@ -284,5 +284,73 @@ fn bench_throughput(c: &mut Criterion) {
group.finish();
}
criterion_group!(benches, bench_compile, bench_match, bench_throughput);
/// End-to-end search throughput, driven through the real `uumain` entry point
/// so the whole pipeline (input buffering, searcher, output) is exercised.
///
/// `bench_match` / `bench_throughput` call `Matcher::match_line` on pre-split
/// lines, which measures matching in isolation. They cannot see a change to how
/// the *searcher* feeds data to the matcher (e.g. scanning whole buffers instead
/// of testing one line at a time), because they never run the searcher. These
/// cases do: a literal pattern (which a buffer-at-a-time engine can accelerate)
/// and an extended-regex control (which cannot), over a multi-megabyte file.
fn bench_search(c: &mut Criterion) {
use std::ffi::OsString;
// A log-like file large enough to cross many internal read buffers.
let mut content = String::new();
for i in 0..80_000u32 {
if i % 100 == 0 {
content.push_str(&format!(
"2024-01-15 10:30:{:02} ERROR worker-{i} connection reset\n",
i % 60
));
} else {
content.push_str(&format!(
"2024-01-15 10:30:{:02} INFO worker-{i} request handled in {}ms\n",
i % 60,
i % 1000
));
}
}
assert!(content.len() > 4 * 1024 * 1024);
let mut path = std::env::temp_dir();
path.push(format!("uu_grep_bench_{}.log", std::process::id()));
std::fs::write(&path, &content).unwrap();
let path_arg = path.clone().into_os_string();
// `-q` with a pattern that never matches forces a full scan of the file and
// produces no output, so the timing reflects pure scanning throughput.
let run = |extra_flag: Option<&str>, pattern: &str| {
let mut args: Vec<OsString> = vec![OsString::from("grep"), OsString::from("-q")];
if let Some(flag) = extra_flag {
args.push(OsString::from(flag));
}
args.push(OsString::from(pattern));
args.push(path_arg.clone());
// No match => Err(exit code 1); we only care about the work, not status.
let _ = uu_grep::uumain(args.into_iter());
};
let mut group = c.benchmark_group("search");
group.bench_function("scan_literal_no_match", |b| {
b.iter(|| run(None, black_box("NONEXISTENT_TOKEN_XYZ")))
});
group.bench_function("scan_regex_no_match", |b| {
b.iter(|| run(Some("-E"), black_box("NON[0-9]EXISTENT_TOKEN")))
});
group.finish();
let _ = std::fs::remove_file(&path);
}
criterion_group!(
benches,
bench_compile,
bench_match,
bench_throughput,
bench_search
);
criterion_main!(benches);
+6
View File
@@ -864,6 +864,12 @@ fn expand_num_shorthand(args: impl Iterator<Item = OsString>) -> Vec<OsString> {
out
}
impl Default for GlobSet {
fn default() -> Self {
Self::new()
}
}
impl GlobSet {
/// Create an empty GlobSet.
pub fn new() -> Self {