mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
expr: add a benchmark (#12578)
This commit is contained in:
@@ -38,6 +38,7 @@ jobs:
|
||||
uu_du,
|
||||
uu_echo,
|
||||
uu_expand,
|
||||
uu_expr,
|
||||
uu_fold,
|
||||
uu_hostname,
|
||||
uu_join,
|
||||
|
||||
Generated
+1
@@ -3521,6 +3521,7 @@ name = "uu_expr"
|
||||
version = "0.9.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"codspeed-divan-compat",
|
||||
"fluent",
|
||||
"num-bigint",
|
||||
"num-traits",
|
||||
|
||||
@@ -27,6 +27,14 @@ uucore = { workspace = true, features = ["i18n-collator"] }
|
||||
thiserror = { workspace = true }
|
||||
fluent = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
divan = { workspace = true }
|
||||
uucore = { workspace = true, features = ["benchmark"] }
|
||||
|
||||
[[bin]]
|
||||
name = "expr"
|
||||
path = "src/main.rs"
|
||||
|
||||
[[bench]]
|
||||
name = "expr_bench"
|
||||
harness = false
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
// This file is part of the uutils coreutils package.
|
||||
//
|
||||
// For the full copyright and license information, please view the LICENSE
|
||||
// file that was distributed with this source code.
|
||||
|
||||
use divan::{Bencher, black_box};
|
||||
use uu_expr::uumain;
|
||||
use uucore::benchmark::run_util_function;
|
||||
|
||||
/// Benchmark `expr index` worst case: the needle char set never matches, so the
|
||||
/// whole string is scanned. This is the input that exercised the old O(N * M)
|
||||
/// behavior.
|
||||
#[divan::bench]
|
||||
fn index_no_match(bencher: Bencher) {
|
||||
let left = "A".repeat(100_000);
|
||||
let right = "B".repeat(100_000);
|
||||
|
||||
bencher.bench(|| {
|
||||
black_box(run_util_function(uumain, &["index", &left, &right]));
|
||||
});
|
||||
}
|
||||
|
||||
/// Benchmark `expr index` with a match near the end of the string.
|
||||
#[divan::bench]
|
||||
fn index_match_at_end(bencher: Bencher) {
|
||||
let mut left = "A".repeat(100_000);
|
||||
left.push('Z');
|
||||
let right = "Z".repeat(100_000);
|
||||
|
||||
bencher.bench(|| {
|
||||
black_box(run_util_function(uumain, &["index", &left, &right]));
|
||||
});
|
||||
}
|
||||
|
||||
fn main() {
|
||||
divan::main();
|
||||
}
|
||||
Reference in New Issue
Block a user