Skip to content

Instantly share code, notes, and snippets.

@IceCereal
Created April 30, 2020 17:06
Show Gist options
  • Save IceCereal/b2813cbd842c102828b9a4396e3af866 to your computer and use it in GitHub Desktop.
Save IceCereal/b2813cbd842c102828b9a4396e3af866 to your computer and use it in GitHub Desktop.
Record the time taken for compressing a file of size [0..2Mb..2.5Kb] using tar, gunzip and zip.
#!/bin/bash
# To run this:
# > create a file called program.sh
# > $ chmod +x program.sh
# > $ ./program.sh
# Note:
# > keep if=/dev/urandom if you want a randomized file
# > keep if=path/to/filename if you want a structured file (which is dependent on your file)
#
# Alternatively, you could make a 2mb file using /dev/urandom once and keep that as the structured file
# in the event you don't want to generate a random file every time the loop function is called.
function capture (){
echo "File Size $1";
echo "Generating file...";
# if = /dev/urandom for random data
# if = path/to/file for structured data (that's dependent on your file)
dd if=/dev/urandom bs=$1 count=1 > orig_file.txt;
echo "FILE SIZE: $1" >> capture.txt;
echo "Creating tarball...";
{ time tar -cf generated_tarball.tar orig_file.txt; } 2>> capture.txt;
echo "Creating gunzip...";
{ time tar -czf generated_gunzip.tar.gz orig_file.txt; } 2>> capture.txt;
echo "Creating zip...";
{ time zip generated_zip.zip orig_file.txt; } 2>> capture.txt;
echo "Recording size...";
ls -l generated_* >> capture.txt;
rm generated_*;
rm orig_file.txt;
}
echo "Begin Capture-Time-Taken-To-Compress-File..."
# 0Kb to 2Mb with increments of 2500 bytes
for i in {0..2000000..2500}
do
capture $i;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment