mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
sort: update DEFAULT_BUF_SIZE to 8 KiB
This commit is contained in:
committed by
Daniel Hofstetter
parent
1a781b4346
commit
121f1c5982
@@ -28,8 +28,9 @@ pub const BASE_CMD_PARSE_ERROR: i32 = 1;
|
||||
///
|
||||
/// This default is only used if no "-w"/"--wrap" argument is passed
|
||||
pub const WRAP_DEFAULT: usize = 76;
|
||||
// Fixed to 8 KiB (equivalent to std::io::DEFAULT_BUF_SIZE on most targets)
|
||||
pub const DEFAULT_BUFFER_SIZE: usize = 8 * 1024;
|
||||
|
||||
// Fixed to 8 KiB (equivalent to `std::sys::io::DEFAULT_BUF_SIZE` on most targets)
|
||||
pub const DEFAULT_BUF_SIZE: usize = 8 * 1024;
|
||||
|
||||
pub struct Config {
|
||||
pub decode: bool,
|
||||
@@ -151,15 +152,12 @@ pub fn get_input(config: &Config) -> UResult<Box<dyn BufRead>> {
|
||||
Some(path_buf) => {
|
||||
let file =
|
||||
File::open(path_buf).map_err_context(|| path_buf.maybe_quote().to_string())?;
|
||||
Ok(Box::new(BufReader::with_capacity(
|
||||
DEFAULT_BUFFER_SIZE,
|
||||
file,
|
||||
)))
|
||||
Ok(Box::new(BufReader::with_capacity(DEFAULT_BUF_SIZE, file)))
|
||||
}
|
||||
None => {
|
||||
// Stdin is already buffered by the OS; wrap once more to reduce syscalls per read.
|
||||
Ok(Box::new(BufReader::with_capacity(
|
||||
DEFAULT_BUFFER_SIZE,
|
||||
DEFAULT_BUF_SIZE,
|
||||
io::stdin(),
|
||||
)))
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ fn sort_unique_locale(bencher: Bencher, num_lines: usize) {
|
||||
});
|
||||
}
|
||||
|
||||
/// Benchmark sorting with very long lines exceeding START_BUFFER_SIZE (8000 bytes)
|
||||
/// Benchmark sorting with very long lines exceeding `DEFAULT_BUF_SIZE` (8192 bytes)
|
||||
#[divan::bench(args = [10_000])]
|
||||
fn sort_long_line(bencher: Bencher, line_size: usize) {
|
||||
// Create files with very long lines to test buffer handling
|
||||
|
||||
@@ -36,7 +36,8 @@ use crate::{
|
||||
use crate::{Line, print_sorted};
|
||||
|
||||
// Note: update `test_sort::test_start_buffer` if this size is changed
|
||||
const START_BUFFER_SIZE: usize = 8_000;
|
||||
// Fixed to 8 KiB (equivalent to `std::sys::io::DEFAULT_BUF_SIZE` on most targets)
|
||||
const DEFAULT_BUF_SIZE: usize = 8 * 1024;
|
||||
|
||||
/// Sort files by using auxiliary files for storing intermediate chunks (if needed), and output the result.
|
||||
pub fn ext_sort(
|
||||
@@ -224,11 +225,7 @@ fn read_write_loop<I: WriteableTmpFile>(
|
||||
for _ in 0..2 {
|
||||
let should_continue = chunks::read(
|
||||
&sender,
|
||||
RecycledChunk::new(if START_BUFFER_SIZE < buffer_size {
|
||||
START_BUFFER_SIZE
|
||||
} else {
|
||||
buffer_size
|
||||
}),
|
||||
RecycledChunk::new(buffer_size.min(DEFAULT_BUF_SIZE)),
|
||||
Some(buffer_size),
|
||||
&mut carry_over,
|
||||
&mut file,
|
||||
|
||||
Reference in New Issue
Block a user