Skip to content

Commit 1005caa

Browse files
committed
Added some minor optimisations for a 6% perf improvement
1 parent 122fb24 commit 1005caa

File tree

14 files changed

+331
-318
lines changed

14 files changed

+331
-318
lines changed

Cargo.lock

Lines changed: 23 additions & 67 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ members = ["cli-excel-rs", "crates/*", "py-excel-rs"]
33
resolver = "2"
44

55
[workspace.package]
6-
version = "0.5.5"
6+
version = "0.6.0"
77
authors = ["Carl Voller"]
88
edition = "2021"
99
homepage = "https://github.com/carlvoller/excel-rs"
1010
license = "MIT"
1111
repository = "https://github.com/carlvoller/excel-rs"
1212

1313
[workspace.dependencies]
14-
excel-rs-xlsx = { version = "0.5.5", path = "crates/excel-rs-xlsx", default-features = false }
15-
excel-rs-csv = { version = "0.5.5", path = "crates/excel-rs-csv", default-features = false }
16-
excel-rs-postgres = { version = "0.5.5", path = "crates/excel-rs-postgres", default-features = false }
14+
excel-rs-xlsx = { version = "0.6.0", path = "crates/excel-rs-xlsx", default-features = false }
15+
excel-rs-csv = { version = "0.6.0", path = "crates/excel-rs-csv", default-features = false }
16+
excel-rs-postgres = { version = "0.6.0", path = "crates/excel-rs-postgres", default-features = false }
1717

1818
[profile.release]
1919
opt-level = 3
2020
lto = "fat"
2121
debug = true
2222
overflow-checks = false
23-
debug-assertions = false
23+
debug-assertions = false

benchmarks/test-py-excel-rs.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
import py_excel_rs
2-
from datetime import datetime, timezone, timedelta
3-
import pandas as pd
42

5-
naive_date = datetime.now()
6-
tz_date = datetime.now(timezone(timedelta(hours=8)))
7-
8-
data = [[naive_date, tz_date, "hello", 10, 10.888]]
9-
df = pd.DataFrame(data, columns=["Date", "Timezone Date", "hi", "number1", "float2"])
10-
11-
xlsx = py_excel_rs.df_to_xlsx(df, should_infer_types=False)
3+
f = open('organizations-1000000.csv', 'rb')
4+
xlsx = py_excel_rs.csv_to_xlsx(f.read())
125

136
with open('report.xlsx', 'wb') as f:
147
f.write(xlsx)

cli-excel-rs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cli-excel-rs"
3-
version = "0.3.0"
3+
version = "0.4.0"
44
authors.workspace = true
55
edition.workspace = true
66
homepage.workspace = true

cli-excel-rs/src/main.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,13 @@ fn main() {
3232

3333
let output_buffer = vec![];
3434
let mut workbook = WorkBook::new(Cursor::new(output_buffer));
35-
let mut worksheet = workbook.get_worksheet(String::from("Sheet 1"));
35+
let worksheet = workbook.get_worksheet(String::from("Sheet 1"));
36+
37+
if let Err(e) = worksheet {
38+
panic!("{e}");
39+
}
40+
41+
let mut worksheet = worksheet.unwrap();
3642

3743
let mut reader = bytes_to_csv(data.as_slice());
3844
let headers = get_headers(&mut reader);

crates/excel-rs-postgres/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub use sql_impl::{ExcelBytes, ExcelBytesBorrowed};
1414
pub fn postgres_to_xlsx<'a>(mut iter: RowIter<'a>) -> Result<Vec<u8>> {
1515
let output_buffer = vec![];
1616
let mut workbook = WorkBook::new(Cursor::new(output_buffer));
17-
let mut worksheet = workbook.get_worksheet(String::from("Sheet 1"));
17+
let mut worksheet = workbook.get_worksheet(String::from("Sheet 1"))?;
1818

1919
let headers = iter.next().ok().unwrap().unwrap();
2020
let len = headers.len();

crates/excel-rs-xlsx/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ readme = "../../README.md"
99
description = "xlsx processor for excel-rs"
1010

1111
[dependencies]
12-
zip = { version = "2.2.0", default-features = false, features = [
12+
zip = { version = "4.6.1", default-features = false, features = [
1313
"deflate-flate2",
14-
"deflate-zlib-ng",
14+
"deflate-flate2-zlib-rs",
1515
] }
1616
anyhow = "1.0.86"

crates/excel-rs-xlsx/src/format.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ impl<W: Write + Seek> XlsxFormatter<W> {
2727
// }
2828

2929
pub fn finish(mut self, num_of_sheets: u16) -> Result<W> {
30-
let options = SimpleFileOptions::default();
30+
let options = SimpleFileOptions::default()
31+
.compression_method(zip::CompressionMethod::Deflated)
32+
.compression_level(Some(1));
3133
self.write_content_type(&options, num_of_sheets)?;
3234
self.write_rels(&options)?;
3335
self.write_doc_props(&options)?;

0 commit comments

Comments
 (0)