refactor(bench): unify line counting in get_file_info to use count_existing_lines

Reuse the existing count_existing_lines() (reader.lines().count())
instead of a manual read_until loop, eliminating duplicate line-counting
logic in data_gen.rs.

Closes #40
This commit is contained in:
dailz
2026-06-05 17:04:46 +08:00
parent a8b64e78bd
commit 5656b26d7b

View File

@@ -21,15 +21,7 @@ pub fn ensure_test_file(path: &Path) -> std::io::Result<TestFileInfo> {
fn get_file_info(path: &Path) -> std::io::Result<TestFileInfo> {
let metadata = fs::metadata(path)?;
let size_bytes = metadata.len();
let file = fs::File::open(path)?;
let mut reader = BufReader::new(file);
let mut line_count: u64 = 0;
let mut buf = Vec::new();
while reader.read_until(b'\n', &mut buf)? > 0 {
line_count += 1;
buf.clear();
}
let line_count = count_existing_lines(path)?;
let avg_line_length = if line_count > 0 {
size_bytes as f64 / line_count as f64