LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to calculate time required for compressing using zip? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-calculate-time-required-for-compressing-using-zip-659739/)

newuser31 08-01-2008 08:09 AM

How to calculate time required for compressing using zip?
 
Hello All,

I need to compress a tar file using zip in a shell script.
Is there any way in which i can estimate the time required to compress the file before actually compressing it using zip?

Thanks,
newuser31

bigrigdriver 08-01-2008 10:39 AM

One way to do it would be three commands in sequence:
1) date (formated to show hour,minute,second)
2) zip filename
3) date

Then subtract first date from second date to get the answer.

Or, try using the time command to time the zip operation.

colucix 08-01-2008 10:51 AM

bigrigdriver, I think the question is about estimating the time needed by the zip command, before actually execute it. My answer is no. The time required by the compression algorithm depends on:
1. the size of the original file
2. the kind of data inside the file
3. the load of the machine
4. the performance of the filesystem I/O
5. ...
you can only do a rough estimate based on the file size, which is the only information you can get in advance. Just my opinion.

salasi 08-01-2008 11:40 AM

Yeah, but...

I would agree that you can't really calculate the time to compress a general file. You might, however, be able to measure the time to compress a similar file, depending on what you know about the files that you are going to want to compress. In many cases, getting an estimate of the worst-case time (greatest time that it could take) is enough. In which cases the 'how do you time...' come into their own.

I'm not sure that OP will get more useful information unless more can be disclosed about the application.

matthewg42 08-01-2008 11:51 AM

It is much more usual to use gzip to compress a .tar file, and there is no need to do it as a separate phase - just add the z option when making the tar file in the first place, and it will be created compressed.

A zipped tarball is unusual. Like tar files, zip files are a "filesystem in a file" - you can store multiple files and so on. They're not as suitable for accessing from a tape drive (which tar files were originally designed to do, but they include compression, which a tar file does not do on it's own.

So I would expect either .zip or .tar.gz (a gzipped tar file), or .tar.bz2 (a tar file compressed with the bzip2 program, which takes longer than gzip, but often results in a smaller size). You might also see .tar.Z, which is a tar file which has been compressed using the unix "compress" program.

Unlike zip, gzip, bzip2 and compress do not contain multiple files - they just contain a compressed version of one file.

I agree with the replies which say it is not really feasible to pre-calculate the time it will take to compress a file. There are too many variables. Your best bet is to do some tests with a system under common working loads, and get a feel for roughly how long it will take. Note that the runtime will rise sharply as the machine becomes heavily loaded.

newuser31 08-01-2008 11:11 PM

Thank you
 
Thank you for all the help and suggestions!

newuser31


All times are GMT -5. The time now is 01:30 AM.