-
Notifications
You must be signed in to change notification settings - Fork 78
New read api #233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
cosmicexplorer
wants to merge
5
commits into
zip-rs:master
Choose a base branch
from
cosmicexplorer:new-read-api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
New read api #233
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e1eb09b
add ZipEntry API in src/unstable/read.rs
cosmicexplorer e4a6fff
add new read API to fuzzer
cosmicexplorer ff2bd63
add benchmarks for iterating through entries
cosmicexplorer f33748b
document how the benchmark was produced and add python script used
cosmicexplorer e46dce8
create ReadableEntry trait to ensure EntryData and Read
cosmicexplorer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
#![cfg(all(feature = "_deflate-any", feature = "bzip2"))] | ||
|
||
use bencher::{benchmark_group, benchmark_main}; | ||
|
||
use std::fs; | ||
use std::io::{self, prelude::*}; | ||
use std::path::Path; | ||
|
||
use bencher::Bencher; | ||
|
||
use zip::read::stream::{ZipStreamFileMetadata, ZipStreamReader, ZipStreamVisitor}; | ||
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. | ||
* 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)?; | ||
ZipArchive::new(file) | ||
} | ||
|
||
fn write_entry_to_sink_generic(bench: &mut Bencher) { | ||
let mut archive = get_test_data().unwrap(); | ||
let total_size: u64 = archive.decompressed_size().unwrap().try_into().unwrap(); | ||
|
||
bench.bytes = total_size; | ||
bench.bench_n(1, |bench| { | ||
bench.iter(|| { | ||
for i in 0..archive.len() { | ||
let mut f = archive.by_index_generic(i).unwrap(); | ||
io::copy(&mut f, &mut io::sink()).unwrap(); | ||
} | ||
}) | ||
}); | ||
} | ||
|
||
fn write_entry_to_sink_standard(bench: &mut Bencher) { | ||
let mut archive = get_test_data().unwrap(); | ||
let total_size: u64 = archive.decompressed_size().unwrap().try_into().unwrap(); | ||
|
||
bench.bytes = total_size; | ||
bench.bench_n(1, |bench| { | ||
bench.iter(|| { | ||
for i in 0..archive.len() { | ||
let mut f = archive.by_index(i).unwrap(); | ||
io::copy(&mut f, &mut io::sink()).unwrap(); | ||
} | ||
}) | ||
}); | ||
} | ||
|
||
fn write_stream_to_sink_generic(bench: &mut Bencher) { | ||
let archive = get_test_data().unwrap(); | ||
let total_size: u64 = archive.decompressed_size().unwrap().try_into().unwrap(); | ||
|
||
let mut reader = archive.into_inner(); | ||
|
||
bench.bytes = total_size; | ||
bench.bench_n(1, |bench| { | ||
bench.iter(|| { | ||
reader.rewind().unwrap(); | ||
let mut stream_zip = StreamingArchive::new(&mut reader); | ||
|
||
while let Some(mut file) = stream_zip.next_entry().unwrap() { | ||
io::copy(&mut file, &mut io::sink()).unwrap(); | ||
} | ||
while stream_zip.next_metadata_entry().unwrap().is_some() {} | ||
}) | ||
}); | ||
} | ||
|
||
fn write_stream_to_sink_standard(bench: &mut Bencher) { | ||
let archive = get_test_data().unwrap(); | ||
let total_size: u64 = archive.decompressed_size().unwrap().try_into().unwrap(); | ||
|
||
struct V; | ||
impl ZipStreamVisitor for V { | ||
fn visit_file(&mut self, file: &mut ZipFile) -> ZipResult<()> { | ||
io::copy(file, &mut io::sink())?; | ||
Ok(()) | ||
} | ||
fn visit_additional_metadata( | ||
&mut self, | ||
_metadata: &ZipStreamFileMetadata, | ||
) -> ZipResult<()> { | ||
Ok(()) | ||
} | ||
} | ||
|
||
let mut reader = archive.into_inner(); | ||
|
||
bench.bytes = total_size; | ||
bench.bench_n(1, |bench| { | ||
bench.iter(|| { | ||
reader.rewind().unwrap(); | ||
let stream_zip = ZipStreamReader::new(&mut reader); | ||
|
||
stream_zip.visit(&mut V).unwrap(); | ||
}) | ||
}); | ||
} | ||
|
||
benchmark_group!( | ||
benches, | ||
write_entry_to_sink_generic, | ||
write_entry_to_sink_standard, | ||
write_stream_to_sink_generic, | ||
write_stream_to_sink_standard, | ||
); | ||
|
||
benchmark_main!(benches); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer
include_bytes!
here, to eliminate the type of disk and the state of the filesystem as potential sources of noise.