Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
- { package: uu_cp }
- { package: uu_cut }
- { package: uu_dd }
- { package: uu_df }
- { package: uu_du }
- { package: uu_expand }
- { package: uu_fold }
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/uu/df/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,14 @@ thiserror = { workspace = true }
fluent = { workspace = true }

[dev-dependencies]
divan = { workspace = true }
tempfile = { workspace = true }
uucore = { workspace = true, features = ["benchmark"] }

[[bin]]
name = "df"
path = "src/main.rs"

[[bench]]
name = "df_bench"
harness = false
52 changes: 52 additions & 0 deletions src/uu/df/benches/df_bench.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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 std::env;
use std::fs;
use std::path::PathBuf;
use tempfile::TempDir;
use uu_df::uumain;
use uucore::benchmark::run_util_function;

fn create_deep_directory(base_dir: &std::path::Path, depth: usize) -> PathBuf {
let mut current = base_dir.to_path_buf();
env::set_current_dir(&current).unwrap();

for _ in 0..depth {
current = current.join("d");
fs::create_dir("d").unwrap();
env::set_current_dir("d").unwrap();
}
current
}

#[divan::bench]
fn df_deep_directory(bencher: Bencher) {
const DEPTH: usize = 20000;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surprised that such a depth is possible :)


let original_dir = env::current_dir().unwrap();
let temp_dir = TempDir::new().unwrap();
let _deep_path = create_deep_directory(temp_dir.path(), DEPTH);
bencher.bench(|| {
black_box(run_util_function(uumain, &[] as &[&str]));
});

env::set_current_dir(original_dir).unwrap();
}

#[divan::bench]
fn df_with_path(bencher: Bencher) {
let temp_dir = TempDir::new().unwrap();
let temp_path_str = temp_dir.path().to_str().unwrap();

bencher.bench(|| {
black_box(run_util_function(uumain, &[temp_path_str]));
});
}

fn main() {
divan::main();
}
Loading