|
6 | 6 | use divan::{Bencher, black_box}; |
7 | 7 | use std::ffi::OsString; |
8 | 8 | use uu_base64::uumain; |
9 | | -use uucore::benchmark::{create_test_file, run_util_function, setup_test_file, text_data}; |
| 9 | +use uucore::benchmark::{create_test_file, run_util_function, text_data}; |
10 | 10 |
|
11 | 11 | fn create_tmp_file(size_mb: usize) -> String { |
| 12 | + let temp_dir = tempfile::tempdir().unwrap(); |
12 | 13 | let data = text_data::generate_by_size(size_mb, 80); |
13 | | - let file_path = setup_test_file(&data); |
| 14 | + let file_path = create_test_file(&data, temp_dir.path()); |
14 | 15 | String::from(file_path.to_str().unwrap()) |
15 | 16 | } |
16 | 17 |
|
17 | 18 | /// Benchmark for base64 encoding |
18 | 19 | #[divan::bench()] |
19 | 20 | fn b64_encode_synthetic(bencher: Bencher) { |
20 | | - let file_path_str = &create_tmp_file(50); |
| 21 | + let file_path_str = &create_tmp_file(5_000); |
21 | 22 |
|
22 | 23 | bencher.bench(|| { |
23 | | - black_box(run_util_function( |
24 | | - uumain, |
25 | | - &["-o", "/dev/null", file_path_str], |
26 | | - )); |
| 24 | + black_box(run_util_function(uumain, &[file_path_str])); |
27 | 25 | }); |
28 | 26 | } |
29 | 27 |
|
30 | 28 | // Benchmark for base64 decoding |
31 | 29 | #[divan::bench()] |
32 | 30 | fn b64_decode_synthetic(bencher: Bencher) { |
33 | 31 | let temp_dir = tempfile::tempdir().unwrap(); |
34 | | - let file_path_str = &create_tmp_file(50); |
| 32 | + let file_path_str = &create_tmp_file(5_000); |
35 | 33 | let in_file = create_test_file(b"", temp_dir.path()); |
36 | 34 | let in_file_str = in_file.to_str().unwrap(); |
37 | 35 | uumain( |
38 | 36 | [ |
39 | | - OsString::from(uucore::util_name()), |
40 | | - OsString::from("-o"), |
41 | | - OsString::from(in_file_str), |
42 | 37 | OsString::from(file_path_str), |
| 38 | + OsString::from(format!(">{in_file_str}")), |
43 | 39 | ] |
44 | 40 | .iter() |
45 | 41 | .map(|x| (*x).clone()), |
46 | 42 | ); |
47 | 43 |
|
48 | 44 | bencher.bench(|| { |
49 | | - black_box(run_util_function( |
50 | | - uumain, |
51 | | - &["-d", "-o", "/dev/null", in_file_str], |
52 | | - )); |
| 45 | + black_box(run_util_function(uumain, &["-d", in_file_str])); |
53 | 46 | }); |
54 | 47 | } |
55 | 48 |
|
56 | 49 | // Benchmark different file sizes for base64 decoding ignoring garbage characters |
57 | 50 | #[divan::bench()] |
58 | 51 | fn b64_decode_ignore_garbage_synthetic(bencher: Bencher) { |
59 | 52 | let temp_dir = tempfile::tempdir().unwrap(); |
60 | | - let file_path_str = &create_tmp_file(50); |
| 53 | + let file_path_str = &create_tmp_file(5_000); |
61 | 54 | let in_file = create_test_file(b"", temp_dir.path()); |
62 | 55 | let in_file_str = in_file.to_str().unwrap(); |
63 | 56 | uumain( |
64 | 57 | [ |
65 | | - OsString::from(uucore::util_name()), |
66 | | - OsString::from("-o"), |
67 | | - OsString::from(in_file_str), |
68 | 58 | OsString::from(file_path_str), |
| 59 | + OsString::from(format!(">{in_file_str}")), |
69 | 60 | ] |
70 | 61 | .iter() |
71 | 62 | .map(|x| (*x).clone()), |
72 | 63 | ); |
73 | 64 |
|
74 | 65 | bencher.bench(|| { |
75 | | - black_box(run_util_function( |
76 | | - uumain, |
77 | | - &["-d", "-i", "-o", "/dev/null", in_file_str], |
78 | | - )); |
| 66 | + black_box(run_util_function(uumain, &["-d", "-i", in_file_str])); |
79 | 67 | }); |
80 | 68 | } |
81 | 69 |
|
|
0 commit comments