mirror of
https://github.com/uutils/grep.git
synced 2026-06-10 16:15:11 -07:00
Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b46a86d48a | ||
|
|
b0164440e3 | ||
|
|
96762f26ca | ||
|
|
c8dfef6563 | ||
|
|
ddac723054 |
@@ -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]
|
||||
@@ -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
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user