aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.functions11
1 files changed, 6 insertions, 5 deletions
diff --git a/.functions b/.functions
index 93356f9..c2c1556 100644
--- a/.functions
+++ b/.functions
@@ -52,12 +52,13 @@ function phpserver() {
php -S "${ip}:${port}"
}
-# Get gzipped file size
+# Compare original and gzipped file size
function gz() {
- echo "orig size (bytes): "
- cat "$1" | wc -c
- echo "gzipped size (bytes): "
- gzip -c "$1" | wc -c
+ local origsize=$(wc -c < "$1")
+ local gzipsize=$(gzip -c "$1" | wc -c)
+ local ratio=$(echo "$gzipsize * 100/ $origsize" | bc -l)
+ printf "orig: %d bytes\n" "$origsize"
+ printf "gzip: %d bytes (%2.2f%%)\n" "$gzipsize" "$ratio"
}
# Test if HTTP compression (RFC 2616 + SDCH) is enabled for a given URL.