Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ wasm-bindgen-test = "^0.3.56"

[dev-dependencies]
bencher = "0.1"
criterion = "0.5"
getrandom = { version = "0.4", default-features = false }
walkdir = "2.5"
time = { version = "^0.3.47", features = ["formatting", "macros"] }
Expand Down Expand Up @@ -134,3 +135,7 @@ harness = false
[[bench]]
name = "merge_archive"
harness = false

[[bench]]
name = "deflate_alloc"
harness = false
41 changes: 41 additions & 0 deletions benches/deflate_alloc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use criterion::{criterion_group, criterion_main, Criterion, BenchmarkId, Throughput};
use std::io::{Cursor, Write};
use zip::write::SimpleFileOptions;
use zip::ZipWriter;
use zip::CompressionMethod;

fn bench_many_small_files(c: &mut Criterion) {
let mut group = c.benchmark_group("deflate_many_small");
for n in [10, 100, 500].iter() {
let data = vec![b'x'; 1024];
group.throughput(Throughput::Bytes((*n as u64)*1024));
group.bench_with_input(BenchmarkId::new("deflate", n), n, |b, &n| {
b.iter(|| {
let buf = Cursor::new(Vec::new());
let mut zip = ZipWriter::new(buf);
let opts = SimpleFileOptions::default().compression_method(CompressionMethod::DEFLATE);
for i in 0..n {
zip.start_file(format!("file_{:04}.txt", i), opts).unwrap();
zip.write_all(&data).unwrap();
}
zip.finish().unwrap()
})
});
group.bench_with_input(BenchmarkId::new("stored", n), n, |b, &n| {
b.iter(|| {
let buf = Cursor::new(Vec::new());
let mut zip = ZipWriter::new(buf);
let opts = SimpleFileOptions::default().compression_method(CompressionMethod::Stored);
for i in 0..n {
zip.start_file(format!("file_{:04}.txt", i), opts).unwrap();
zip.write_all(&data).unwrap();
}
zip.finish().unwrap()
})
});
}
group.finish();
}

criterion_group!(benches, bench_many_small_files);
criterion_main!(benches);
Loading