Skip to content
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

Compression speed too low #34

Open
erenturkm opened this issue Aug 17, 2023 · 3 comments
Open

Compression speed too low #34

erenturkm opened this issue Aug 17, 2023 · 3 comments

Comments

@erenturkm
Copy link

Hi,

I am using sevenz-rust version 0.4.3, with Rust 1.71 on Windows. I am using the code below:
`
use std::path::{Path, PathBuf};
use std::fs::{File,OpenOptions};
use sevenz_rust::lzma::{LZMA2Options ,LZMA2Reader,LZMA2Writer};
use sevenz_rust::{SevenZReader, SevenZWriter, Password, SevenZArchiveEntry};
use std::{process::exit};
use std::time::Instant;

fn main() {
let verb_duration=Instant::now();
let file_name="testdir\folder1\file3.txt";
let file_path=PathBuf::from(file_name);

let archive_path=PathBuf::from("test.7z");
let file_handle = File::create(archive_path).unwrap();
let mut zip:SevenZWriter<File>;
let res_zipwriter=SevenZWriter::new(file_handle);
match res_zipwriter {
    Ok(z)=>{zip=z;}
    Err(e)=>{exit(1)}
}
let entry_name=file_name.replace("\\", "/");
let zipentry= SevenZArchiveEntry::from_path(file_path.clone(),entry_name);
let file_handle=File::open(file_path.clone()).unwrap();
let res_write=zip.push_archive_entry(zipentry,Some(file_handle));
zip.finish();
println!("{:?}",verb_duration.elapsed());

}
`
file3.txt is a 50MB text file and above code takes 54 seconds to generate 9 KB file.
When I use 7zip archiver, it takes less than a second and generates 9KB file.
I am hoping that there is a setting that I am missing to speed things up?

@dyz1990
Copy link
Owner

dyz1990 commented Aug 18, 2023

@erenturkm Did you run this code in release mode?

@erenturkm
Copy link
Author

No, it was debug mode, I tried it with release mode and its taking 4.2 seconds which is still less than %25 speed of the original archiver. Since I will be using it for very large text files (100MB+), I need a solution that is minimum %75 slower, preferably better than the original solution.

@dyz1990
Copy link
Owner

dyz1990 commented Aug 19, 2023

At present, the compression speed can only be increased by reducing the compression rate.But the compressed file will also become larger

zip.set_content_methods(vec![
            LZMA2Options::with_preset(3).into(),//preset: from 1 to 9, default  6
        ]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants