Debian Codegraph @

src/uu/df/benches/df_bench.rs

raw
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 std::env;
8 use std::fs;
9 use std::path::PathBuf;
10 use tempfile::TempDir;
11 use uu_df::uumain;
12 use uucore::benchmark::get_bench_args;
13
14 fn create_deep_directory(base_dir: &std::path::Path, depth: usize) -> PathBuf {
15 let mut current = base_dir.to_path_buf();
16 env::set_current_dir(&current).unwrap();
17
18 for _ in 0..depth {
19 current = current.join("d");
20 fs::create_dir("d").unwrap();
21 env::set_current_dir("d").unwrap();
22 }
23 current
24 }
25
26 #[divan::bench]
27 fn df_deep_directory(bencher: Bencher) {
28 const DEPTH: usize = 20000;
29
30 let original_dir = env::current_dir().unwrap();
31 let temp_dir = TempDir::new().unwrap();
32 let _deep_path = create_deep_directory(temp_dir.path(), DEPTH);
33
34 bencher
35 .with_inputs(|| get_bench_args(&[]).into_iter())
36 .bench_values(|args| black_box(uumain(args)));
37
38 env::set_current_dir(original_dir).unwrap();
39 }
40
41 fn main() {
42 divan::main();
43 }