| 1 |
#[cfg(unix)] |
| 2 |
use divan::{Bencher, black_box}; |
| 3 |
#[cfg(unix)] |
| 4 |
use uu_tee::uumain; |
| 5 |
#[cfg(unix)] |
| 6 |
use uucore::benchmark::{run_util_function, setup_test_file}; |
| 7 |
|
| 8 |
#[cfg(unix)] |
| 9 |
#[divan::bench(args = [10_000_000])] |
| 10 |
fn tee_stdin_file(bencher: Bencher, size_bytes: usize) { |
| 11 |
let data = vec![b'a'; size_bytes]; |
| 12 |
let file_path = setup_test_file(&data); |
| 13 |
let file = std::fs::File::open(file_path).unwrap(); |
| 14 |
let stdin_bak = rustix::io::dup(rustix::stdio::stdin()).unwrap(); |
| 15 |
|
| 16 |
bencher.bench_local(|| { |
| 17 |
use rustix::stdio::dup2_stdin; |
| 18 |
rustix::fs::seek(&file, rustix::fs::SeekFrom::Start(0)).unwrap(); |
| 19 |
dup2_stdin(&file).unwrap(); // should be 1 thread |
| 20 |
black_box(run_util_function(uumain, &[])); |
| 21 |
dup2_stdin(&stdin_bak).unwrap(); // should be 1 thread |
| 22 |
}); |
| 23 |
} |
| 24 |
|
| 25 |
fn main() { |
| 26 |
divan::main(); |
| 27 |
} |