mirror of
https://github.com/uutils/coreutils.git
synced 2026-05-06 07:26:38 -04:00
tee: add benchmark (#12134)
This commit is contained in:
@@ -48,6 +48,7 @@ jobs:
|
|||||||
uu_shuf,
|
uu_shuf,
|
||||||
uu_sort,
|
uu_sort,
|
||||||
uu_split,
|
uu_split,
|
||||||
|
uu_tee,
|
||||||
uu_timeout,
|
uu_timeout,
|
||||||
uu_tsort,
|
uu_tsort,
|
||||||
uu_unexpand,
|
uu_unexpand,
|
||||||
|
|||||||
Generated
+2
@@ -4256,8 +4256,10 @@ name = "uu_tee"
|
|||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
|
"codspeed-divan-compat",
|
||||||
"fluent",
|
"fluent",
|
||||||
"rustix",
|
"rustix",
|
||||||
|
"tempfile",
|
||||||
"uucore",
|
"uucore",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
+10
-2
@@ -24,9 +24,17 @@ clap = { workspace = true }
|
|||||||
uucore = { workspace = true, features = ["libc", "parser", "signals"] }
|
uucore = { workspace = true, features = ["libc", "parser", "signals"] }
|
||||||
fluent = { workspace = true }
|
fluent = { workspace = true }
|
||||||
|
|
||||||
[target.'cfg(unix)'.dev-dependencies]
|
[dev-dependencies]
|
||||||
rustix = { workspace = true }
|
divan = { workspace = true }
|
||||||
|
rustix = { workspace = true, features = ["stdio", "fs"] }
|
||||||
|
tempfile = { workspace = true }
|
||||||
|
uucore = { workspace = true, features = ["benchmark"] }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "tee"
|
name = "tee"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
|
|
||||||
|
[[bench]]
|
||||||
|
name = "tee_bench"
|
||||||
|
harness = false
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#[cfg(unix)]
|
||||||
|
use divan::{Bencher, black_box};
|
||||||
|
#[cfg(unix)]
|
||||||
|
use uu_tee::uumain;
|
||||||
|
#[cfg(unix)]
|
||||||
|
use uucore::benchmark::{run_util_function, setup_test_file};
|
||||||
|
|
||||||
|
#[cfg(unix)]
|
||||||
|
#[divan::bench(args = [10_000_000])]
|
||||||
|
fn tee_stdin_file(bencher: Bencher, size_bytes: usize) {
|
||||||
|
let data = vec![b'a'; size_bytes];
|
||||||
|
let file_path = setup_test_file(&data);
|
||||||
|
let file = std::fs::File::open(file_path).unwrap();
|
||||||
|
let stdin_bak = rustix::io::dup(rustix::stdio::stdin()).unwrap();
|
||||||
|
|
||||||
|
bencher.bench_local(|| {
|
||||||
|
use rustix::stdio::dup2_stdin;
|
||||||
|
rustix::fs::seek(&file, rustix::fs::SeekFrom::Start(0)).unwrap();
|
||||||
|
dup2_stdin(&file).unwrap(); // should be 1 thread
|
||||||
|
black_box(run_util_function(uumain, &[]));
|
||||||
|
dup2_stdin(&stdin_bak).unwrap(); // should be 1 thread
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
divan::main();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user