Skip to content

Instantly share code, notes, and snippets.

@animatedlew
Last active March 24, 2019 17:38
Show Gist options
  • Save animatedlew/381498ca1106583a76049acf13c67965 to your computer and use it in GitHub Desktop.
Save animatedlew/381498ca1106583a76049acf13c67965 to your computer and use it in GitHub Desktop.
#!/bin/bash -e
usage() { echo "tarch file"; }
if [[ -z $1 ]]; then usage; exit 1; fi
total=$(tar cf - "$1" | wc -c)
gzip=$(tar czf - "$1" | wc -c)
bzip2=$(tar cjf - "$1" | wc -c)
gzip_goal=$(echo "scale=2; ${gzip} / ${total} * 100" | bc)
bzip2_goal=$(echo "scale=2; ${bzip2} / ${total} * 100" | bc)
printf "gzip :${gzip}B %4s%s\n" "$gzip_goal" "%"
printf "bzip2:${bzip2}B %4s%s\n" "$bzip2_goal" "%"
echo "total:${total}B"
echo
# set green
tput setaf 2
if [[ $gzip_goal < $bzip2_goal ]]
then
delta=$(echo "$bzip2_goal - $gzip_goal" | bc)
echo "It turns out that gzip is ~${delta}% smaller than bzip2. A miracle!"
else
delta=$(echo "$gzip_goal - $bzip2_goal" | bc)
printf "bzip2 is %0.f%s smaller than gzip.\n" "${delta}" "%"
fi
# set normal
tput sgr0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment