| 1 |
// This file is part of the uutils coreutils package. |
| 2 |
// |
| 3 |
// For the full copyright and license information, please view the LICENSE |
| 4 |
// file that was distributed with this source code. |
| 5 |
|
| 6 |
use divan::{Bencher, black_box}; |
| 7 |
use uu_expr::uumain; |
| 8 |
use uucore::benchmark::run_util_function; |
| 9 |
|
| 10 |
/// Benchmark `expr index` worst case: the needle char set never matches, so the |
| 11 |
/// whole string is scanned. This is the input that exercised the old O(N * M) |
| 12 |
/// behavior. |
| 13 |
#[divan::bench] |
| 14 |
fn index_no_match(bencher: Bencher) { |
| 15 |
let left = "A".repeat(100_000); |
| 16 |
let right = "B".repeat(100_000); |
| 17 |
|
| 18 |
bencher.bench(|| { |
| 19 |
black_box(run_util_function(uumain, &["index", &left, &right])); |
| 20 |
}); |
| 21 |
} |
| 22 |
|
| 23 |
/// Benchmark `expr index` with a match near the end of the string. |
| 24 |
#[divan::bench] |
| 25 |
fn index_match_at_end(bencher: Bencher) { |
| 26 |
let mut left = "A".repeat(100_000); |
| 27 |
left.push('Z'); |
| 28 |
let right = "Z".repeat(100_000); |
| 29 |
|
| 30 |
bencher.bench(|| { |
| 31 |
black_box(run_util_function(uumain, &["index", &left, &right])); |
| 32 |
}); |
| 33 |
} |
| 34 |
|
| 35 |
fn main() { |
| 36 |
divan::main(); |
| 37 |
} |