From 99a0fa0bbbd7d3f38f332402489a34bb2ab8fecb Mon Sep 17 00:00:00 2001 From: Johann Tuffe Date: Wed, 1 Nov 2023 22:35:51 +0800 Subject: [PATCH] update benches --- benches/basic.rs | 39 ++++++++++++++++++++++++++++++++++++++- src/ods.rs | 16 ++++++++-------- 2 files changed, 46 insertions(+), 9 deletions(-) diff --git a/benches/basic.rs b/benches/basic.rs index 69146d9e..15117186 100644 --- a/benches/basic.rs +++ b/benches/basic.rs @@ -17,7 +17,6 @@ fn count>>(path: &str) -> usize { count += excel .worksheet_range(&s) .unwrap() - .unwrap() .rows() .flat_map(|r| r.iter()) .count(); @@ -44,3 +43,41 @@ fn bench_xlsb(b: &mut Bencher) { fn bench_ods(b: &mut Bencher) { b.iter(|| count::>("tests/issues.ods")); } + +#[bench] +fn bench_xlsx_cells_reader(b: &mut Bencher) { + fn count>>(path: &str) -> usize { + let path = format!("{}/{}", env!("CARGO_MANIFEST_DIR"), path); + let mut excel: Xlsx<_> = open_workbook(&path).expect("cannot open excel file"); + + let sheets = excel.sheet_names().to_owned(); + let mut count = 0; + for s in sheets { + let mut cells_reader = excel.worksheet_cells_reader(&s).unwrap(); + while let Some(_) = cells_reader.next_cell().unwrap() { + count += 1; + } + } + count + } + b.iter(|| count::>("tests/issues.xlsx")); +} + +#[bench] +fn bench_xlsb_cells_reader(b: &mut Bencher) { + fn count>>(path: &str) -> usize { + let path = format!("{}/{}", env!("CARGO_MANIFEST_DIR"), path); + let mut excel: Xlsb<_> = open_workbook(&path).expect("cannot open excel file"); + + let sheets = excel.sheet_names().to_owned(); + let mut count = 0; + for s in sheets { + let mut cells_reader = excel.worksheet_cells_reader(&s).unwrap(); + while let Some(_) = cells_reader.next_cell().unwrap() { + count += 1; + } + } + count + } + b.iter(|| count::>("tests/issues.xlsb")); +} diff --git a/src/ods.rs b/src/ods.rs index cefe9626..45c436d2 100644 --- a/src/ods.rs +++ b/src/ods.rs @@ -69,14 +69,14 @@ from_err!(std::num::ParseFloatError, OdsError, ParseFloat); impl std::fmt::Display for OdsError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - OdsError::Io(e) => write!(f, "I/O error: {}", e), - OdsError::Zip(e) => write!(f, "Zip error: {:?}", e), - OdsError::Xml(e) => write!(f, "Xml error: {}", e), - OdsError::XmlAttr(e) => write!(f, "Xml attribute error: {}", e), - OdsError::Parse(e) => write!(f, "Parse string error: {}", e), - OdsError::ParseInt(e) => write!(f, "Parse integer error: {}", e), - OdsError::ParseFloat(e) => write!(f, "Parse float error: {}", e), - OdsError::ParseBool(e) => write!(f, "Parse bool error: {}", e), + OdsError::Io(e) => write!(f, "I/O error: {e}"), + OdsError::Zip(e) => write!(f, "Zip error: {e:?}"), + OdsError::Xml(e) => write!(f, "Xml error: {e}"), + OdsError::XmlAttr(e) => write!(f, "Xml attribute error: {e}"), + OdsError::Parse(e) => write!(f, "Parse string error: {e}"), + OdsError::ParseInt(e) => write!(f, "Parse integer error: {e}"), + OdsError::ParseFloat(e) => write!(f, "Parse float error: {e}"), + OdsError::ParseBool(e) => write!(f, "Parse bool error: {e}"), OdsError::InvalidMime(mime) => write!(f, "Invalid MIME type: {mime:?}"), OdsError::FileNotFound(file) => write!(f, "'{file}' file not found in archive"), OdsError::Eof(node) => write!(f, "Expecting '{node}' node, found end of xml file"),