Skip to content

Commit d403ba0

Browse files
authored
Revert "Fix base64 benchmarks (uutils#9082)"
This reverts commit 975e18c.
1 parent 975e18c commit d403ba0

File tree

4 files changed

+14
-46
lines changed

4 files changed

+14
-46
lines changed

docs/src/extensions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ Similar to the proc-ps implementation and unlike GNU/Coreutils, `uptime` provide
195195

196196
## `base32/base64/basenc`
197197

198-
Just like on macOS, `base32/base64/basenc` provides `-D` to decode data and `-o` to output to a file.
198+
Just like on macOS, `base32/base64/basenc` provides `-D` to decode data.
199199

200200
## `shred`
201201

src/uu/base32/locales/en-US.ftl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,3 @@ base-common-read-error = read error: {$error}
5757
base-common-help-decode = decode data
5858
base-common-help-ignore-garbage = when decoding, ignore non-alphabetic characters
5959
base-common-help-wrap = wrap encoded lines after COLS character (default {$default}, 0 to disable wrapping)
60-
base-common-help-output-file = output to OUTPUT_FILE instead of stdout

src/uu/base32/src/base_common.rs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use clap::{Arg, ArgAction, Command};
99
use std::ffi::OsString;
1010
use std::fs::File;
11-
use std::io::{self, BufWriter, ErrorKind, Read, Seek, Write};
11+
use std::io::{self, ErrorKind, Read, Seek};
1212
use std::path::{Path, PathBuf};
1313
use uucore::display::Quotable;
1414
use uucore::encoding::{
@@ -34,15 +34,13 @@ pub struct Config {
3434
pub ignore_garbage: bool,
3535
pub wrap_cols: Option<usize>,
3636
pub to_read: Option<PathBuf>,
37-
pub output_file: Option<PathBuf>,
3837
}
3938

4039
pub mod options {
4140
pub static DECODE: &str = "decode";
4241
pub static WRAP: &str = "wrap";
4342
pub static IGNORE_GARBAGE: &str = "ignore-garbage";
4443
pub static FILE: &str = "file";
45-
pub static OUTPUT_FILE: &str = "output_file";
4644
}
4745

4846
impl Config {
@@ -88,17 +86,11 @@ impl Config {
8886
})
8987
.transpose()?;
9088

91-
let output_file = match options.get_one::<OsString>(options::OUTPUT_FILE) {
92-
Some(value) if value != "-" => Some(Path::new(value).to_owned()),
93-
_ => None,
94-
};
95-
9689
Ok(Self {
9790
decode: options.get_flag(options::DECODE),
9891
ignore_garbage: options.get_flag(options::IGNORE_GARBAGE),
9992
wrap_cols,
10093
to_read,
101-
output_file,
10294
})
10395
}
10496
}
@@ -146,14 +138,6 @@ pub fn base_app(about: &'static str, usage: &str) -> Command {
146138
.help(translate!("base-common-help-wrap", "default" => WRAP_DEFAULT))
147139
.overrides_with(options::WRAP),
148140
)
149-
.arg(
150-
Arg::new(options::OUTPUT_FILE)
151-
.short('o')
152-
.long(options::OUTPUT_FILE)
153-
.help(translate!("base-common-help-output-file"))
154-
.value_parser(clap::value_parser!(OsString))
155-
.value_hint(clap::ValueHint::FilePath),
156-
)
157141
// "multiple" arguments are used to check whether there is more than one
158142
// file passed in.
159143
.arg(
@@ -210,10 +194,7 @@ pub fn handle_input<R: Read + Seek>(input: &mut R, format: Format, config: Confi
210194
get_supports_fast_decode_and_encode(format, config.decode, has_padding);
211195

212196
let supports_fast_decode_and_encode_ref = supports_fast_decode_and_encode.as_ref();
213-
let mut stdout_lock: Box<dyn Write> = match &config.output_file {
214-
Some(path) => Box::new(BufWriter::new(File::create(path)?)),
215-
None => Box::new(io::stdout().lock()),
216-
};
197+
let mut stdout_lock = io::stdout().lock();
217198
if config.decode {
218199
fast_decode::fast_decode(
219200
read,

src/uu/base64/benches/base64_bench.rs

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,76 +6,64 @@
66
use divan::{Bencher, black_box};
77
use std::ffi::OsString;
88
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};
1010

1111
fn create_tmp_file(size_mb: usize) -> String {
12+
let temp_dir = tempfile::tempdir().unwrap();
1213
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());
1415
String::from(file_path.to_str().unwrap())
1516
}
1617

1718
/// Benchmark for base64 encoding
1819
#[divan::bench()]
1920
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);
2122

2223
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]));
2725
});
2826
}
2927

3028
// Benchmark for base64 decoding
3129
#[divan::bench()]
3230
fn b64_decode_synthetic(bencher: Bencher) {
3331
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);
3533
let in_file = create_test_file(b"", temp_dir.path());
3634
let in_file_str = in_file.to_str().unwrap();
3735
uumain(
3836
[
39-
OsString::from(uucore::util_name()),
40-
OsString::from("-o"),
41-
OsString::from(in_file_str),
4237
OsString::from(file_path_str),
38+
OsString::from(format!(">{in_file_str}")),
4339
]
4440
.iter()
4541
.map(|x| (*x).clone()),
4642
);
4743

4844
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]));
5346
});
5447
}
5548

5649
// Benchmark different file sizes for base64 decoding ignoring garbage characters
5750
#[divan::bench()]
5851
fn b64_decode_ignore_garbage_synthetic(bencher: Bencher) {
5952
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);
6154
let in_file = create_test_file(b"", temp_dir.path());
6255
let in_file_str = in_file.to_str().unwrap();
6356
uumain(
6457
[
65-
OsString::from(uucore::util_name()),
66-
OsString::from("-o"),
67-
OsString::from(in_file_str),
6858
OsString::from(file_path_str),
59+
OsString::from(format!(">{in_file_str}")),
6960
]
7061
.iter()
7162
.map(|x| (*x).clone()),
7263
);
7364

7465
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]));
7967
});
8068
}
8169

0 commit comments

Comments
 (0)