#!/bin/bash

declare -A b
declare -A k

printf "    %-24s %11s %11s %11s %11s\n" File Raw Min Zip Min/Zip
for file in $@; do
  b[raw]=$(cat $file | wc -c)
  b[min]=$(cat $file | uglifyjs | wc -c)
  alt=$(cat $file | uglifyjs --lift-vars | wc -c)
  if [ $alt -lt ${b[min]} ]; then
    b[min]=$alt
  fi
  b[zip]=$(cat $file | gzip -c  | wc -c)
  b[minzip]=$(cat $file | uglifyjs | gzip -c | wc -c)
  alt=$(cat $file | uglifyjs --lift-vars | gzip -c | wc -c)
  if [ $alt -lt ${b[minzip]} ]; then
    b[minzip]=$alt
  fi
  for field in raw min zip minzip; do
    k[$field]=$(echo "${b[$field]} / 1024" | bc -l)
  done
  printf "    %-24s" $file
  for field in raw min zip minzip; do
    printf "%6d/%05.2f" ${b[$field]} ${k[$field]}
  done
  printf "\n"
done
