Skip to content

Commit

Permalink
document how the benchmark was produced and add python script used
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed Aug 21, 2024
1 parent ff2bd63 commit f33748b
Show file tree
Hide file tree
Showing 3 changed files with 6,527 additions and 6 deletions.
19 changes: 13 additions & 6 deletions benches/decompress_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use bencher::{benchmark_group, benchmark_main};

use std::fs;
use std::io::prelude::*;
use std::io::{self, prelude::*};
use std::path::Path;

use bencher::Bencher;
Expand All @@ -13,7 +13,14 @@ use zip::read::ZipFile;
use zip::unstable::read::streaming::StreamingArchive;
use zip::{result::ZipResult, ZipArchive};

/* This contains the compressed text of King Lear from Project Gutenberg, in the public domain. */
/* This contains the compressed text of King Lear from Project Gutenberg, in the public domain.
* It contains the text of King Lear in multiple formats:
* 1. Stored (uncompressed)
* 2. Deflated (compresslevel=9)
* 3. Bzip2 (compresslevel=9)
* It contains 50 of each, with 150 entries total. This is generated by the script
* tests/data/generate-king-lear-zip.py.
*/
fn get_test_data() -> ZipResult<ZipArchive<fs::File>> {
let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/data/king-lear-compressed.zip");
let file = fs::File::open(path)?;
Expand All @@ -29,7 +36,7 @@ fn write_entry_to_sink_generic(bench: &mut Bencher) {
bench.iter(|| {
for i in 0..archive.len() {
let mut f = archive.by_index_generic(i).unwrap();
std::io::copy(&mut f, &mut std::io::sink()).unwrap();
io::copy(&mut f, &mut io::sink()).unwrap();
}
})
});
Expand All @@ -44,7 +51,7 @@ fn write_entry_to_sink_standard(bench: &mut Bencher) {
bench.iter(|| {
for i in 0..archive.len() {
let mut f = archive.by_index(i).unwrap();
std::io::copy(&mut f, &mut std::io::sink()).unwrap();
io::copy(&mut f, &mut io::sink()).unwrap();
}
})
});
Expand All @@ -63,7 +70,7 @@ fn write_stream_to_sink_generic(bench: &mut Bencher) {
let mut stream_zip = StreamingArchive::new(&mut reader);

while let Some(mut file) = stream_zip.next_entry().unwrap() {
std::io::copy(&mut file, &mut std::io::sink()).unwrap();
io::copy(&mut file, &mut io::sink()).unwrap();
}
while stream_zip.next_metadata_entry().unwrap().is_some() {}
})
Expand All @@ -77,7 +84,7 @@ fn write_stream_to_sink_standard(bench: &mut Bencher) {
struct V;
impl ZipStreamVisitor for V {
fn visit_file(&mut self, file: &mut ZipFile) -> ZipResult<()> {
std::io::copy(file, &mut std::io::sink())?;
io::copy(file, &mut io::sink())?;
Ok(())
}
fn visit_additional_metadata(
Expand Down
Loading

0 comments on commit f33748b

Please sign in to comment.