Last active
February 24, 2022 07:35
-
-
Save yunginnanet/d33049500f2d868f1896779397544915 to your computer and use it in GitHub Desktop.
Compare a blob of datas size while gzipped and base64'd. I use this when I'm packing things into binaries with base64 and gzip to calculate the benefits of gzip vs the extra overhead of base64.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function gzipCompare() { | |
_TARG="$1" | |
echo -n "Calculating gzip differences for"; echo -e " \e[1;32m$_TARG\e[0m" | |
_OG=$(cat "$1" | wc -c) | |
_B6=$(cat "$1" | base64 -w 0 | wc -c) | |
_GZ=$(cat "$1" | gzip -9 | wc -c) | |
_G6=$(cat "$1" | gzip -9 | base64 -w 0 | wc -c) | |
echo "----------------------------------------" | |
echo -n "Original: " | colorize white --attr="bold"; | |
echo "$_OG bytes" | |
echo -n "Base64'd: " | colorize blue --attr="bold"; | |
echo -n "$_B6" | colorize blue; echo " bytes" | |
echo -n "Gzippe'd: " | colorize yellow --attr="bold"; | |
echo -n "$_GZ" | colorize yellow; echo " bytes" | |
echo -n "Gzip+B64: " | colorize magenta --attr="bold"; | |
echo -n "$_G6" | colorize magenta; echo " bytes" | |
echo "----------------------------------------" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment