Skip to content
Open
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
19 changes: 14 additions & 5 deletions src/uu/du/benches/du_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// 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 divan::{black_box, Bencher};
use tempfile::TempDir;
use uu_du::uumain;
use uucore::benchmark::{fs_tree, get_bench_args};
Expand Down Expand Up @@ -59,43 +59,51 @@ fn du_human_balanced_tree(
}
*/

/// Benchmark du on wide directory structures (many files/dirs, shallow)
/// Run a throwaway traversal to warm the OS page/inode cache before timing.
fn warm_cache(path: &std::path::Path) {
let _ = black_box(uumain(get_bench_args(&[&path]).into_iter()));
}
Comment on lines +62 to +65

/// Benchmark du on wide directory structures (many files/dirs, shallow).
#[divan::bench(args = [(5000, 500)])]
fn du_wide_tree(bencher: Bencher, (total_files, total_dirs): (usize, usize)) {
let temp_dir = TempDir::new().unwrap();
let temp_path = temp_dir.path();
fs_tree::create_wide_tree(temp_path, total_files, total_dirs);
warm_cache(temp_path);

bencher
.with_inputs(|| get_bench_args(&[&temp_path]).into_iter())
.bench_values(|args| black_box(uumain(args)));
}

/// Benchmark du -a on wide directory structures
/// Benchmark du -a on wide directory structures.
#[divan::bench(args = [(5000, 500)])]
fn du_all_wide_tree(bencher: Bencher, (total_files, total_dirs): (usize, usize)) {
let temp_dir = TempDir::new().unwrap();
let temp_path = temp_dir.path();
fs_tree::create_wide_tree(temp_path, total_files, total_dirs);
warm_cache(temp_path);

bencher
.with_inputs(|| get_bench_args(&[&"-a", &temp_path]).into_iter())
.bench_values(|args| black_box(uumain(args)));
Comment on lines 82 to 90
}

/// Benchmark du on deep directory structures
/// Benchmark du on deep directory structures.
#[divan::bench(args = [(100, 3)])]
fn du_deep_tree(bencher: Bencher, (depth, files_per_level): (usize, usize)) {
let temp_dir = TempDir::new().unwrap();
let temp_path = temp_dir.path();
fs_tree::create_deep_tree(temp_path, depth, files_per_level);
warm_cache(temp_path);

bencher
.with_inputs(|| get_bench_args(&[&temp_path]).into_iter())
.bench_values(|args| black_box(uumain(args)));
}

/// Benchmark du -s (summarize) on balanced tree
/// Benchmark du -s (summarize) on balanced tree.
#[divan::bench(args = [(5, 4, 10)])]
fn du_summarize_balanced_tree(
bencher: Bencher,
Expand All @@ -104,6 +112,7 @@ fn du_summarize_balanced_tree(
let temp_dir = TempDir::new().unwrap();
let temp_path = temp_dir.path();
fs_tree::create_balanced_tree(temp_path, depth, dirs_per_level, files_per_dir);
warm_cache(temp_path);

bencher
.with_inputs(|| get_bench_args(&[&"-s", &temp_path]).into_iter())
Expand Down
Loading