| 1 |
// This file is part of the uutils coreutils package. |
| 2 |
// |
| 3 |
// For the full copyright and license information, please view the LICENSE |
| 4 |
// file that was distributed with this source code. |
| 5 |
|
| 6 |
use divan::{Bencher, black_box}; |
| 7 |
use tempfile::TempDir; |
| 8 |
use uu_du::uumain; |
| 9 |
use uucore::benchmark::{fs_tree, get_bench_args}; |
| 10 |
|
| 11 |
/* too much variance |
| 12 |
/// Benchmark default du on balanced tree |
| 13 |
#[divan::bench(args = [(5, 4, 10)])] |
| 14 |
fn du_balanced_tree( |
| 15 |
bencher: Bencher, |
| 16 |
(depth, dirs_per_level, files_per_dir): (usize, usize, usize), |
| 17 |
) { |
| 18 |
let temp_dir = TempDir::new().unwrap(); |
| 19 |
let temp_path = temp_dir.path(); |
| 20 |
fs_tree::create_balanced_tree(temp_path, depth, dirs_per_level, files_per_dir); |
| 21 |
|
| 22 |
bencher |
| 23 |
.with_inputs(|| get_bench_args(&[&temp_path])) |
| 24 |
.bench_values(|args| black_box(uumain(args))); |
| 25 |
} |
| 26 |
*/ |
| 27 |
|
| 28 |
/* too much variance |
| 29 |
/// Benchmark du -a (all files) on balanced tree |
| 30 |
#[divan::bench(args = [(4, 3, 10)])] |
| 31 |
fn du_all_balanced_tree( |
| 32 |
bencher: Bencher, |
| 33 |
(depth, dirs_per_level, files_per_dir): (usize, usize, usize), |
| 34 |
) { |
| 35 |
let temp_dir = TempDir::new().unwrap(); |
| 36 |
let temp_path = temp_dir.path(); |
| 37 |
fs_tree::create_balanced_tree(temp_path, depth, dirs_per_level, files_per_dir); |
| 38 |
|
| 39 |
bencher |
| 40 |
.with_inputs(|| get_bench_args(&[&"-a", &temp_path])) |
| 41 |
.bench_values(|args| black_box(uumain(args))); |
| 42 |
} |
| 43 |
*/ |
| 44 |
|
| 45 |
/* too much variance |
| 46 |
/// Benchmark du -h (human readable) on balanced tree |
| 47 |
#[divan::bench(args = [(5, 4, 10)])] |
| 48 |
fn du_human_balanced_tree( |
| 49 |
bencher: Bencher, |
| 50 |
(depth, dirs_per_level, files_per_dir): (usize, usize, usize), |
| 51 |
) { |
| 52 |
let temp_dir = TempDir::new().unwrap(); |
| 53 |
let temp_path = temp_dir.path(); |
| 54 |
fs_tree::create_balanced_tree(temp_path, depth, dirs_per_level, files_per_dir); |
| 55 |
|
| 56 |
bencher |
| 57 |
.with_inputs(|| get_bench_args(&[&"-h", &temp_path])) |
| 58 |
.bench_values(|args| black_box(uumain(args))); |
| 59 |
} |
| 60 |
*/ |
| 61 |
|
| 62 |
/// Run a throwaway traversal to warm the OS page/inode cache before timing. |
| 63 |
fn warm_cache(path: &std::path::Path) { |
| 64 |
let _ = black_box(uumain(get_bench_args(&[&path]).into_iter())); |
| 65 |
} |
| 66 |
|
| 67 |
/// Benchmark du on wide directory structures (many files/dirs, shallow). |
| 68 |
#[divan::bench(args = [(5000, 500)])] |
| 69 |
fn du_wide_tree(bencher: Bencher, (total_files, total_dirs): (usize, usize)) { |
| 70 |
let temp_dir = TempDir::new().unwrap(); |
| 71 |
let temp_path = temp_dir.path(); |
| 72 |
fs_tree::create_wide_tree(temp_path, total_files, total_dirs); |
| 73 |
warm_cache(temp_path); |
| 74 |
|
| 75 |
bencher |
| 76 |
.with_inputs(|| get_bench_args(&[&temp_path]).into_iter()) |
| 77 |
.bench_values(|args| black_box(uumain(args))); |
| 78 |
} |
| 79 |
|
| 80 |
/// Benchmark du -a on wide directory structures |
| 81 |
#[divan::bench(args = [(5000, 500)])] |
| 82 |
fn du_all_wide_tree(bencher: Bencher, (total_files, total_dirs): (usize, usize)) { |
| 83 |
let temp_dir = TempDir::new().unwrap(); |
| 84 |
let temp_path = temp_dir.path(); |
| 85 |
fs_tree::create_wide_tree(temp_path, total_files, total_dirs); |
| 86 |
warm_cache(temp_path); |
| 87 |
|
| 88 |
bencher |
| 89 |
.with_inputs(|| get_bench_args(&[&"-a", &temp_path]).into_iter()) |
| 90 |
.bench_values(|args| black_box(uumain(args))); |
| 91 |
} |
| 92 |
|
| 93 |
/// Benchmark du on deep directory structures |
| 94 |
#[divan::bench(args = [(100, 3)])] |
| 95 |
fn du_deep_tree(bencher: Bencher, (depth, files_per_level): (usize, usize)) { |
| 96 |
let temp_dir = TempDir::new().unwrap(); |
| 97 |
let temp_path = temp_dir.path(); |
| 98 |
fs_tree::create_deep_tree(temp_path, depth, files_per_level); |
| 99 |
warm_cache(temp_path); |
| 100 |
|
| 101 |
bencher |
| 102 |
.with_inputs(|| get_bench_args(&[&temp_path]).into_iter()) |
| 103 |
.bench_values(|args| black_box(uumain(args))); |
| 104 |
} |
| 105 |
|
| 106 |
/// Benchmark du -s (summarize) on balanced tree |
| 107 |
#[divan::bench(args = [(5, 4, 10)])] |
| 108 |
fn du_summarize_balanced_tree( |
| 109 |
bencher: Bencher, |
| 110 |
(depth, dirs_per_level, files_per_dir): (usize, usize, usize), |
| 111 |
) { |
| 112 |
let temp_dir = TempDir::new().unwrap(); |
| 113 |
let temp_path = temp_dir.path(); |
| 114 |
fs_tree::create_balanced_tree(temp_path, depth, dirs_per_level, files_per_dir); |
| 115 |
warm_cache(temp_path); |
| 116 |
|
| 117 |
bencher |
| 118 |
.with_inputs(|| get_bench_args(&[&"-s", &temp_path]).into_iter()) |
| 119 |
.bench_values(|args| black_box(uumain(args))); |
| 120 |
} |
| 121 |
|
| 122 |
fn main() { |
| 123 |
divan::main(); |
| 124 |
} |