From 0faed0baeb5a1735ba14afc4cef17612c6935ec3 Mon Sep 17 00:00:00 2001 From: "codspeed-hq[bot]" <117304815+codspeed-hq[bot]@users.noreply.github.com> Date: Thu, 4 Jun 2026 19:44:08 +0000 Subject: [PATCH 1/2] Add CodSpeed performance benchmarks --- .github/workflows/codspeed.yml | 42 +++++ Cargo.lock | 308 +++++++++++++++++++++++++++++++-- Cargo.toml | 5 + README.md | 1 + benches/bench_tar.rs | 155 +++++++++++++++++ src/uu/tar/src/tar.rs | 4 +- 6 files changed, 495 insertions(+), 20 deletions(-) create mode 100644 .github/workflows/codspeed.yml create mode 100644 benches/bench_tar.rs diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml new file mode 100644 index 0000000..5d03349 --- /dev/null +++ b/.github/workflows/codspeed.yml @@ -0,0 +1,42 @@ +name: CodSpeed + +on: + push: + branches: + - "main" + pull_request: + # `workflow_dispatch` allows CodSpeed to trigger backtest + # performance analysis in order to generate initial data. + workflow_dispatch: + +permissions: + contents: read + id-token: write + +env: + CARGO_TERM_COLOR: always + CARGO_INCREMENTAL: "0" + +jobs: + codspeed: + name: Run benchmarks + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + + - name: Setup rust toolchain + run: | + rustup toolchain install stable --profile minimal + rustup default stable + + - name: Install cargo-codspeed + run: cargo install cargo-codspeed --locked + + - name: Build the benchmark target(s) + run: cargo codspeed build + + - name: Run the benchmarks + uses: CodSpeedHQ/action@v4 + with: + mode: simulation + run: cargo codspeed run diff --git a/Cargo.lock b/Cargo.lock index 0a6769d..306329b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,7 +73,7 @@ version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" dependencies = [ - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -84,7 +84,7 @@ checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" dependencies = [ "anstyle", "once_cell_polyfill", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -93,6 +93,15 @@ version = "1.0.102" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" +[[package]] +name = "approx" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6" +dependencies = [ + "num-traits", +] + [[package]] name = "autocfg" version = "1.5.0" @@ -248,12 +257,88 @@ version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f88a43d011fc4a6876cb7344703e297c71dda42494fee094d5f7c76bf13f746" +[[package]] +name = "codspeed" +version = "4.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57af92d1db7f6871b7e82c79cd87f2501db66f36b0eab924be6ea83dd6b2f3f3" +dependencies = [ + "anyhow", + "cc", + "colored", + "getrandom 0.2.17", + "glob", + "libc", + "nix", + "serde", + "serde_json", + "statrs", +] + +[[package]] +name = "codspeed-divan-compat" +version = "4.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4ea79fd0b1f2128cfac6308369013dba92df47baf4a4f66b57d8158224a361d" +dependencies = [ + "clap", + "codspeed", + "codspeed-divan-compat-macros", + "codspeed-divan-compat-walltime", + "regex", +] + +[[package]] +name = "codspeed-divan-compat-macros" +version = "4.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f70e4ddd6beedefeb48f59d5f85fc21365a66e7976408c3d39f6cbbc4f03e08c" +dependencies = [ + "divan-macros", + "itertools", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "codspeed-divan-compat-walltime" +version = "4.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "490c04f6076be6eacfafb496b8b237f3efbbed93838f2689115cc6f35fcf81c9" +dependencies = [ + "cfg-if", + "clap", + "codspeed", + "condtype", + "divan-macros", + "libc", + "regex-lite", +] + [[package]] name = "colorchoice" version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" +[[package]] +name = "colored" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" +dependencies = [ + "lazy_static", + "windows-sys 0.59.0", +] + +[[package]] +name = "condtype" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf0a07a401f374238ab8e2f11a104d2851bf9ce711ec69804834de8af45c7af" + [[package]] name = "const-oid" version = "0.10.2" @@ -415,6 +500,17 @@ dependencies = [ "syn", ] +[[package]] +name = "divan-macros" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dc51d98e636f5e3b0759a39257458b22619cac7e96d932da6eeb052891bb67c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "dns-lookup" version = "3.0.1" @@ -448,6 +544,12 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" +[[package]] +name = "either" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91622ff5e7162018101f2fea40d6ebf4a78bbe5a49736a2020649edf9693679e" + [[package]] name = "equivalent" version = "1.0.2" @@ -461,7 +563,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" dependencies = [ "libc", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -558,6 +660,17 @@ dependencies = [ "version_check", ] +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + [[package]] name = "getrandom" version = "0.3.4" @@ -707,6 +820,15 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.18" @@ -725,7 +847,7 @@ dependencies = [ "portable-atomic", "portable-atomic-util", "serde_core", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -774,6 +896,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + [[package]] name = "leb128fmt" version = "0.1.0" @@ -1024,6 +1152,15 @@ dependencies = [ "syn", ] +[[package]] +name = "proc-macro-crate" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f" +dependencies = [ + "toml_edit", +] + [[package]] name = "proc-macro2" version = "1.0.106" @@ -1103,6 +1240,12 @@ dependencies = [ "regex-syntax", ] +[[package]] +name = "regex-lite" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab834c73d247e67f4fae452806d17d3c7501756d98c8808d7c9c7aa7d18f973" + [[package]] name = "regex-syntax" version = "0.8.10" @@ -1140,7 +1283,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -1263,7 +1406,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" dependencies = [ "libc", - "windows-sys 0.60.2", + "windows-sys 0.61.2", +] + +[[package]] +name = "statrs" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a3fe7c28c6512e766b0874335db33c94ad7b8f9054228ae1c2abd47ce7d335e" +dependencies = [ + "approx", + "num-traits", ] [[package]] @@ -1302,6 +1455,7 @@ dependencies = [ "clap", "clap_complete", "clap_mangen", + "codspeed-divan-compat", "ctor 1.0.7", "phf", "phf_codegen", @@ -1330,7 +1484,7 @@ dependencies = [ "getrandom 0.4.2", "once_cell", "rustix", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -1340,7 +1494,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "230a1b821ccbd75b185820a1f1ff7b14d21da1e442e22c0863ea5f08771a8874" dependencies = [ "rustix", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -1420,6 +1574,36 @@ dependencies = [ "zerovec", ] +[[package]] +name = "toml_datetime" +version = "1.1.1+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_edit" +version = "0.25.12+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2153edc6955a6c354fad8f5efd38b6a8769bdccf9fe50f8e1329f81b0baa5d7" +dependencies = [ + "indexmap", + "toml_datetime", + "toml_parser", + "winnow", +] + +[[package]] +name = "toml_parser" +version = "1.1.2+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2abe9b86193656635d2411dc43050282ca48aa31c2451210f4202550afb7526" +dependencies = [ + "winnow", +] + [[package]] name = "type-map" version = "0.5.1" @@ -1559,6 +1743,12 @@ version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + [[package]] name = "wasip2" version = "1.0.2+wasi-0.2.9" @@ -1671,7 +1861,7 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -1733,13 +1923,22 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.60.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" dependencies = [ - "windows-targets", + "windows-targets 0.53.5", ] [[package]] @@ -1751,6 +1950,22 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + [[package]] name = "windows-targets" version = "0.53.5" @@ -1758,64 +1973,121 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" dependencies = [ "windows-link", - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm 0.53.1", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + [[package]] name = "windows_aarch64_gnullvm" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + [[package]] name = "windows_aarch64_msvc" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + [[package]] name = "windows_i686_gnu" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + [[package]] name = "windows_i686_gnullvm" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + [[package]] name = "windows_i686_msvc" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + [[package]] name = "windows_x86_64_gnu" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + [[package]] name = "windows_x86_64_gnullvm" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + [[package]] name = "windows_x86_64_msvc" version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" +[[package]] +name = "winnow" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0592e1c9d151f854e6fd382574c3a0855250e1d9b2f99d9281c6e6391af352f1" +dependencies = [ + "memchr", +] + [[package]] name = "wit-bindgen" version = "0.51.0" diff --git a/Cargo.toml b/Cargo.toml index a36b0e2..292a6be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -68,6 +68,7 @@ tar = { optional = true, version = "0.0.1", package = "uu_tar", path = "src/uu/t [dev-dependencies] chrono = { workspace = true } +divan = { version = "4.7.0", package = "codspeed-divan-compat" } pretty_assertions = "1" rand = { workspace = true } regex = { workspace = true } @@ -87,6 +88,10 @@ rlimit = "0.11.0" phf_codegen = { workspace = true } +[[bench]] +name = "bench_tar" +harness = false + [[bin]] name = "tarapp" path = "src/bin/tarapp.rs" diff --git a/README.md b/README.md index 323eb7c..bfd8a42 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ [![dependency status](https://deps.rs/repo/github/uutils/tar/status.svg)](https://deps.rs/repo/github/uutils/tar) [![CodeCov](https://codecov.io/gh/uutils/tar/branch/master/graph/badge.svg)](https://codecov.io/gh/uutils/tar) +[![CodSpeed](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://app.codspeed.io/uutils/tar?utm_source=badge) # tar diff --git a/benches/bench_tar.rs b/benches/bench_tar.rs new file mode 100644 index 0000000..cb11a1c --- /dev/null +++ b/benches/bench_tar.rs @@ -0,0 +1,155 @@ +// Benchmarks for the uutils tar implementation. +// +// These benchmarks exercise the core archive operations (create, list, extract) +// at various scales to track performance over time. + +use std::fs::{self, File}; +use std::io::Write; +use std::path::{Path, PathBuf}; +use tar::operations; +use tempfile::TempDir; + +fn main() { + divan::main(); +} + +/// Create `count` files of `size` bytes each inside `dir`. +fn create_sample_files(dir: &Path, count: usize, size: usize) { + let content = vec![b'A'; size]; + for i in 0..count { + let path = dir.join(format!("file_{i}.txt")); + let mut f = File::create(&path).unwrap(); + f.write_all(&content).unwrap(); + } +} + +/// Collect all regular file paths inside `dir` (non-recursive). +fn collect_files(dir: &Path) -> Vec { + let mut paths: Vec = fs::read_dir(dir) + .unwrap() + .filter_map(|e| e.ok()) + .map(|e| e.path()) + .filter(|p| p.is_file()) + .collect(); + paths.sort(); + paths +} + +/// Build a tar archive at `archive_path` from all files in `source_dir`. +fn build_archive(archive_path: &Path, source_dir: &Path) { + let files = collect_files(source_dir); + let refs: Vec<&Path> = files.iter().map(|p| p.as_path()).collect(); + operations::create::create_archive(archive_path, &refs, false, false).unwrap(); +} + +// --------------------------------------------------------------------------- +// Create benchmarks +// --------------------------------------------------------------------------- + +#[divan::bench] +fn create_archive_10_files(bencher: divan::Bencher) { + let source = TempDir::new().unwrap(); + create_sample_files(source.path(), 10, 4_096); + let files = collect_files(source.path()); + + let out = TempDir::new().unwrap(); + let archive_path = out.path().join("bench.tar"); + + bencher.bench_local(|| { + let refs: Vec<&Path> = files.iter().map(|p| p.as_path()).collect(); + operations::create::create_archive(&archive_path, &refs, false, false).unwrap(); + }); +} + +#[divan::bench] +fn create_archive_100_files(bencher: divan::Bencher) { + let source = TempDir::new().unwrap(); + create_sample_files(source.path(), 100, 4_096); + let files = collect_files(source.path()); + + let out = TempDir::new().unwrap(); + let archive_path = out.path().join("bench.tar"); + + bencher.bench_local(|| { + let refs: Vec<&Path> = files.iter().map(|p| p.as_path()).collect(); + operations::create::create_archive(&archive_path, &refs, false, false).unwrap(); + }); +} + +#[divan::bench] +fn create_archive_directory(bencher: divan::Bencher) { + let source = TempDir::new().unwrap(); + let sub = source.path().join("data"); + fs::create_dir_all(&sub).unwrap(); + create_sample_files(&sub, 30, 4_096); + + let out = TempDir::new().unwrap(); + let archive_path = out.path().join("bench.tar"); + + bencher.bench_local(|| { + operations::create::create_archive(&archive_path, &[sub.as_path()], false, false).unwrap(); + }); +} + +// --------------------------------------------------------------------------- +// List benchmarks +// --------------------------------------------------------------------------- + +#[divan::bench] +fn list_archive_50_files(bencher: divan::Bencher) { + let source = TempDir::new().unwrap(); + create_sample_files(source.path(), 50, 4_096); + let archive_dir = TempDir::new().unwrap(); + let archive_path = archive_dir.path().join("bench.tar"); + build_archive(&archive_path, source.path()); + + bencher.bench_local(|| { + operations::list::list_archive(&archive_path, false).unwrap(); + }); +} + +#[divan::bench] +fn list_archive_verbose_50_files(bencher: divan::Bencher) { + let source = TempDir::new().unwrap(); + create_sample_files(source.path(), 50, 4_096); + let archive_dir = TempDir::new().unwrap(); + let archive_path = archive_dir.path().join("bench.tar"); + build_archive(&archive_path, source.path()); + + bencher.bench_local(|| { + operations::list::list_archive(&archive_path, true).unwrap(); + }); +} + +// --------------------------------------------------------------------------- +// Extract benchmarks +// --------------------------------------------------------------------------- + +#[divan::bench] +fn extract_archive_20_files(bencher: divan::Bencher) { + let source = TempDir::new().unwrap(); + create_sample_files(source.path(), 20, 4_096); + let archive_dir = TempDir::new().unwrap(); + let archive_path = archive_dir.path().join("bench.tar"); + build_archive(&archive_path, source.path()); + + let original_dir = std::env::current_dir().unwrap(); + bencher + .with_inputs(|| TempDir::new().unwrap()) + .bench_local_values(|extract_dir| { + std::env::set_current_dir(extract_dir.path()).unwrap(); + operations::extract::extract_archive(&archive_path, false).unwrap(); + }); + std::env::set_current_dir(original_dir).unwrap(); +} + +// --------------------------------------------------------------------------- +// CLI parsing benchmark +// --------------------------------------------------------------------------- + +#[divan::bench] +fn build_cli_command(bencher: divan::Bencher) { + bencher.bench_local(|| { + divan::black_box(tar::uu_app()); + }); +} diff --git a/src/uu/tar/src/tar.rs b/src/uu/tar/src/tar.rs index 991d4fa..75c1c45 100644 --- a/src/uu/tar/src/tar.rs +++ b/src/uu/tar/src/tar.rs @@ -4,9 +4,9 @@ // file that was distributed with this source code. pub mod errors; -mod operations; +pub mod operations; -use clap::{arg, crate_version, ArgAction, Command}; +use clap::{ArgAction, Command, arg, crate_version}; use std::path::{Path, PathBuf}; use uucore::error::UResult; use uucore::format_usage; From c9f88f0fa2f42a3ad4c7d534c44fbbc156cf93cd Mon Sep 17 00:00:00 2001 From: "codspeed-hq[bot]" <117304815+codspeed-hq[bot]@users.noreply.github.com> Date: Thu, 4 Jun 2026 19:50:28 +0000 Subject: [PATCH 2/2] Fix import ordering to match CI stable toolchain --- src/uu/tar/src/tar.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/uu/tar/src/tar.rs b/src/uu/tar/src/tar.rs index 75c1c45..ff6800f 100644 --- a/src/uu/tar/src/tar.rs +++ b/src/uu/tar/src/tar.rs @@ -6,7 +6,7 @@ pub mod errors; pub mod operations; -use clap::{ArgAction, Command, arg, crate_version}; +use clap::{arg, crate_version, ArgAction, Command}; use std::path::{Path, PathBuf}; use uucore::error::UResult; use uucore::format_usage;