Skip to content

Commit

Permalink
update benches
Browse files Browse the repository at this point in the history
  • Loading branch information
tafia committed Dec 12, 2023
1 parent ce20cc1 commit aa19868
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
39 changes: 38 additions & 1 deletion benches/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ fn count<R: Reader<BufReader<File>>>(path: &str) -> usize {
count += excel
.worksheet_range(&s)
.unwrap()
.unwrap()
.rows()
.flat_map(|r| r.iter())
.count();
Expand All @@ -44,3 +43,41 @@ fn bench_xlsb(b: &mut Bencher) {
fn bench_ods(b: &mut Bencher) {
b.iter(|| count::<Ods<_>>("tests/issues.ods"));
}

#[bench]
fn bench_xlsx_cells_reader(b: &mut Bencher) {
fn count<R: Reader<BufReader<File>>>(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::<Xlsx<_>>("tests/issues.xlsx"));
}

#[bench]
fn bench_xlsb_cells_reader(b: &mut Bencher) {
fn count<R: Reader<BufReader<File>>>(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::<Xlsx<_>>("tests/issues.xlsb"));
}
16 changes: 8 additions & 8 deletions src/ods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit aa19868

Please sign in to comment.