dyz1990 / sevenz-rust

A 7z decompressor/compressor lib written in pure rust
Apache License 2.0
146 stars 24 forks source link

Compression speed too low #34

Open erenturkm opened 11 months ago

erenturkm commented 11 months ago

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 commented 11 months ago

@erenturkm Did you run this code in release mode?

erenturkm commented 11 months ago

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 commented 11 months ago

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
        ]);