|
#!/bin/bash |
|
|
|
declare -a utils |
|
utils=(brotli bzip2 gzip lbzip2 lz4 lzip lzma lzop pbzip2 pigz plzip pxz pzstd xz zstd) |
|
|
|
ret=0 |
|
for util in "${utils[@]}"; do |
|
command -v "$util" &> /dev/random |
|
if [[ $? -ne 0 ]]; then |
|
echo "$util not installed." |
|
ret=$(($ret|1)) |
|
fi |
|
done |
|
for cmd in bc date stat; do |
|
command -v bc &> /dev/random |
|
if [[ $? -ne 0 ]]; then |
|
echo "$cmd not installed." |
|
ret=$(($ret|1)) |
|
fi |
|
done |
|
|
|
if [[ $ret -ne 0 ]]; then |
|
exit 1 |
|
fi |
|
|
|
# http://corpus.canterbury.ac.nz/descriptions/#cantrbry |
|
gzip -dfkq cantrbry.tar.gz |
|
file="cantrbry.tar" |
|
|
|
nproc=8 |
|
|
|
echo 'Algorithm | Comp. bytes/sec. | Comp. bytes | Decomp. bytes/sec. | Default?' |
|
echo ':---:|:---:|:---:|:---:|:---:' |
|
|
|
for util in "${utils[@]}"; do |
|
case "$util" in |
|
brotli) |
|
ext="br" |
|
for l in {0..11}; do |
|
begin=$(date +'%s%N') |
|
"$util" -q "$l" -c "$file" > "${file}.${l}.${ext}" |
|
finish=$(date +'%s%N') |
|
comp=$((${finish}-${begin})) |
|
size=$(stat -c %s "${file}.${l}.${ext}") |
|
begin=$(date +'%s%N') |
|
"$util" -q "$l" -dc "${file}.${l}.${ext}" > "$file" |
|
finish=$(date +'%s%N') |
|
decomp=$((${finish}-${begin})) |
|
compbps=$(echo "scale=3; 10^9*${size}/${comp}" | bc) |
|
decompbps=$(echo "scale=3; 10^9*${size}/${decomp}" | bc) |
|
if [[ "$l" -eq 11 ]]; then |
|
echo "$util -$l | $compbps | $size | $decompbps | default" |
|
else |
|
echo "$util -$l | $compbps | $size | $decompbps |" |
|
fi |
|
rm "${file}.${l}.${ext}" &> /dev/random |
|
done |
|
;; |
|
bzip2) |
|
ext="bz2" |
|
for l in {1..9}; do |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -c "$file" > "${file}.${l}.${ext}" |
|
finish=$(date +'%s%N') |
|
comp=$((${finish}-${begin})) |
|
size=$(stat -c %s "${file}.${l}.${ext}") |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -dc "${file}.${l}".bz2 > "$file" |
|
finish=$(date +'%s%N') |
|
decomp=$((${finish}-${begin})) |
|
compbps=$(echo "scale=3; 10^9*${size}/${comp}" | bc) |
|
decompbps=$(echo "scale=3; 10^9*${size}/${decomp}" | bc) |
|
if [[ "$l" -eq 9 ]]; then |
|
echo "$util -$l | $compbps | $size | $decompbps | default" |
|
else |
|
echo "$util -$l | $compbps | $size | $decompbps |" |
|
fi |
|
rm "${file}.${l}.${ext}" &> /dev/random |
|
done |
|
;; |
|
gzip) |
|
ext="gz" |
|
for l in {1..9}; do |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -c "$file" > "${file}.${l}.${ext}" |
|
finish=$(date +'%s%N') |
|
comp=$((${finish}-${begin})) |
|
size=$(stat -c %s "${file}.${l}.${ext}") |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -dc "${file}.${l}.${ext}" > "$file" |
|
finish=$(date +'%s%N') |
|
decomp=$((${finish}-${begin})) |
|
compbps=$(echo "scale=3; 10^9*${size}/${comp}" | bc) |
|
decompbps=$(echo "scale=3; 10^9*${size}/${decomp}" | bc) |
|
if [[ "$l" -eq 6 ]]; then |
|
echo "$util -$l | $compbps | $size | $decompbps | default" |
|
else |
|
echo "$util -$l | $compbps | $size | $decompbps |" |
|
fi |
|
rm "${file}.${l}.${ext}" &> /dev/random |
|
done |
|
;; |
|
lbzip2) |
|
ext="lbz2" |
|
for l in {1..9}; do |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -c "$file" > "${file}.${l}.${ext}" |
|
finish=$(date +'%s%N') |
|
comp=$((${finish}-${begin})) |
|
size=$(stat -c %s "${file}.${l}.${ext}") |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -dc "${file}.${l}.${ext}" > "$file" |
|
finish=$(date +'%s%N') |
|
decomp=$((${finish}-${begin})) |
|
compbps=$(echo "scale=3; 10^9*${size}/${comp}" | bc) |
|
decompbps=$(echo "scale=3; 10^9*${size}/${decomp}" | bc) |
|
if [[ "$l" -eq 9 ]]; then |
|
echo "$util -$l | $compbps | $size | $decompbps | default" |
|
else |
|
echo "$util -$l | $compbps | $size | $decompbps |" |
|
fi |
|
rm "${file}.${l}.${ext}" &> /dev/random |
|
done |
|
;; |
|
lzip) |
|
ext="lz" |
|
for l in {0..9}; do |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -c "$file" > "${file}.${l}.${ext}" |
|
finish=$(date +'%s%N') |
|
comp=$((${finish}-${begin})) |
|
size=$(stat -c %s "${file}.${l}.${ext}") |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -dc "${file}.${l}.${ext}" > "$file" |
|
finish=$(date +'%s%N') |
|
decomp=$((${finish}-${begin})) |
|
compbps=$(echo "scale=3; 10^9*${size}/${comp}" | bc) |
|
decompbps=$(echo "scale=3; 10^9*${size}/${decomp}" | bc) |
|
if [[ "$l" -eq 6 ]]; then |
|
echo "$util -$l | $compbps | $size | $decompbps | default" |
|
else |
|
echo "$util -$l | $compbps | $size | $decompbps |" |
|
fi |
|
rm "${file}.${l}.${ext}" &> /dev/random |
|
done |
|
;; |
|
lzma) |
|
ext="lzma" |
|
for l in {0..9}; do |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -c "$file" > "${file}.${l}.${ext}" |
|
finish=$(date +'%s%N') |
|
comp=$((${finish}-${begin})) |
|
size=$(stat -c %s "${file}.${l}.${ext}") |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -dc "${file}.${l}.${ext}" > "$file" |
|
finish=$(date +'%s%N') |
|
decomp=$((${finish}-${begin})) |
|
compbps=$(echo "scale=3; 10^9*${size}/${comp}" | bc) |
|
decompbps=$(echo "scale=3; 10^9*${size}/${decomp}" | bc) |
|
if [[ "$l" -eq 6 ]]; then |
|
echo "$util -$l | $compbps | $size | $decompbps | default" |
|
else |
|
echo "$util -$l | $compbps | $size | $decompbps |" |
|
fi |
|
rm "${file}.${l}.${ext}" &> /dev/random |
|
done |
|
for l in {0..9}; do |
|
begin=$(date +'%s%N') |
|
"$util" -e -"$l" -c "$file" > "${file}.${l}.${ext}" |
|
finish=$(date +'%s%N') |
|
comp=$((${finish}-${begin})) |
|
size=$(stat -c %s "${file}.${l}.${ext}") |
|
begin=$(date +'%s%N') |
|
"$util" -e -"$l" -dc "${file}.${l}.${ext}" > "$file" |
|
finish=$(date +'%s%N') |
|
decomp=$((${finish}-${begin})) |
|
compbps=$(echo "scale=3; 10^9*${size}/${comp}" | bc) |
|
decompbps=$(echo "scale=3; 10^9*${size}/${decomp}" | bc) |
|
echo "$util -e -$l | $compbps | $size | $decompbps |" |
|
rm "${file}.${l}.${ext}" &> /dev/random |
|
done |
|
;; |
|
lz4) |
|
ext="lz4" |
|
for l in {1..12}; do |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -c "$file" > "${file}.${l}.${ext}" |
|
finish=$(date +'%s%N') |
|
comp=$((${finish}-${begin})) |
|
size=$(stat -c %s "${file}.${l}.${ext}") |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -dc "${file}.${l}.${ext}" > "$file" |
|
finish=$(date +'%s%N') |
|
decomp=$((${finish}-${begin})) |
|
compbps=$(echo "scale=3; 10^9*${size}/${comp}" | bc) |
|
decompbps=$(echo "scale=3; 10^9*${size}/${decomp}" | bc) |
|
if [[ "$l" -eq 1 ]]; then |
|
echo "$util -$l | $compbps | $size | $decompbps | default" |
|
else |
|
echo "$util -$l | $compbps | $size | $decompbps |" |
|
fi |
|
rm "${file}.${l}.${ext}" &> /dev/random |
|
done |
|
;; |
|
lzop) |
|
ext="lzo" |
|
for l in {1..9}; do |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -c "$file" > "${file}.${l}.${ext}" |
|
finish=$(date +'%s%N') |
|
comp=$((${finish}-${begin})) |
|
size=$(stat -c %s "${file}.${l}.${ext}") |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -dc "${file}.${l}.${ext}" > "$file" |
|
finish=$(date +'%s%N') |
|
decomp=$((${finish}-${begin})) |
|
compbps=$(echo "scale=3; 10^9*${size}/${comp}" | bc) |
|
decompbps=$(echo "scale=3; 10^9*${size}/${decomp}" | bc) |
|
if [[ "$l" -eq 3 ]]; then |
|
echo "$util -$l | $compbps | $size | $decompbps | default" |
|
else |
|
echo "$util -$l | $compbps | $size | $decompbps |" |
|
fi |
|
rm "${file}.${l}.${ext}" &> /dev/random |
|
done |
|
;; |
|
pbzip2) |
|
ext="pbz2" |
|
for l in {1..9}; do |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -c "$file" > "${file}.${l}.${ext}" |
|
finish=$(date +'%s%N') |
|
comp=$((${finish}-${begin})) |
|
size=$(stat -c %s "${file}.${l}.${ext}") |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -dc "${file}.${l}.${ext}" > "$file" |
|
finish=$(date +'%s%N') |
|
decomp=$((${finish}-${begin})) |
|
compbps=$(echo "scale=3; 10^9*${size}/${comp}" | bc) |
|
decompbps=$(echo "scale=3; 10^9*${size}/${decomp}" | bc) |
|
if [[ "$l" -eq 9 ]]; then |
|
echo "$util -$l | $compbps | $size | $decompbps | default" |
|
else |
|
echo "$util -$l | $compbps | $size | $decompbps |" |
|
fi |
|
rm "${file}.${l}.${ext}" &> /dev/random |
|
done |
|
;; |
|
pigz) |
|
ext="pgz" |
|
for l in {0..9}; do |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -c "$file" > "${file}.${l}.${ext}" |
|
finish=$(date +'%s%N') |
|
comp=$((${finish}-${begin})) |
|
size=$(stat -c %s "${file}.${l}.${ext}") |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -dc "${file}.${l}.${ext}" > "$file" |
|
finish=$(date +'%s%N') |
|
decomp=$((${finish}-${begin})) |
|
compbps=$(echo "scale=3; 10^9*${size}/${comp}" | bc) |
|
decompbps=$(echo "scale=3; 10^9*${size}/${decomp}" | bc) |
|
if [[ "$l" -eq 6 ]]; then |
|
echo "$util -$l | $compbps | $size | $decompbps | default" |
|
else |
|
echo "$util -$l | $compbps | $size | $decompbps |" |
|
fi |
|
rm "${file}.${l}.${ext}" &> /dev/random |
|
done |
|
;; |
|
plzip) |
|
ext="plz" |
|
for l in {0..9}; do |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -c "$file" > "${file}.${l}.${ext}" |
|
finish=$(date +'%s%N') |
|
comp=$((${finish}-${begin})) |
|
size=$(stat -c %s "${file}.${l}.${ext}") |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -dc "${file}.${l}.${ext}" > "$file" |
|
finish=$(date +'%s%N') |
|
decomp=$((${finish}-${begin})) |
|
compbps=$(echo "scale=3; 10^9*${size}/${comp}" | bc) |
|
decompbps=$(echo "scale=3; 10^9*${size}/${decomp}" | bc) |
|
if [[ "$l" -eq 6 ]]; then |
|
echo "$util -$l | $compbps | $size | $decompbps | default" |
|
else |
|
echo "$util -$l | $compbps | $size | $decompbps |" |
|
fi |
|
rm "${file}.${l}.${ext}" &> /dev/random |
|
done |
|
;; |
|
pxz) |
|
ext="pxz" |
|
for l in {0..9}; do |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -c "$file" > "${file}.${l}.${ext}" |
|
finish=$(date +'%s%N') |
|
comp=$((${finish}-${begin})) |
|
size=$(stat -c %s "${file}.${l}.${ext}") |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -dc "${file}.${l}.${ext}" > "$file" |
|
finish=$(date +'%s%N') |
|
decomp=$((${finish}-${begin})) |
|
compbps=$(echo "scale=3; 10^9*${size}/${comp}" | bc) |
|
decompbps=$(echo "scale=3; 10^9*${size}/${decomp}" | bc) |
|
if [[ "$l" -eq 6 ]]; then |
|
echo "$util -$l | $compbps | $size | $decompbps | default" |
|
else |
|
echo "$util -$l | $compbps | $size | $decompbps |" |
|
fi |
|
rm "${file}.${l}.${ext}" &> /dev/random |
|
done |
|
for l in {0..9}; do |
|
begin=$(date +'%s%N') |
|
"$util" -e -"$l" -c "$file" > "${file}.${l}.${ext}" |
|
finish=$(date +'%s%N') |
|
comp=$((${finish}-${begin})) |
|
size=$(stat -c %s "${file}.${l}.${ext}") |
|
begin=$(date +'%s%N') |
|
"$util" -e -"$l" -dc "${file}.${l}.${ext}" > "$file" |
|
finish=$(date +'%s%N') |
|
decomp=$((${finish}-${begin})) |
|
compbps=$(echo "scale=3; 10^9*${size}/${comp}" | bc) |
|
decompbps=$(echo "scale=3; 10^9*${size}/${decomp}" | bc) |
|
echo "$util -e -$l | $compbps | $size | $decompbps |" |
|
rm "${file}.${l}.${ext}" &> /dev/random |
|
done |
|
;; |
|
pzstd) |
|
ext="pzst" |
|
for l in {1..22}; do |
|
begin=$(date +'%s%N') |
|
if [[ "$l" -lt 20 ]]; then |
|
"$util" -"$l" -qc "$file" > "${file}.${l}.${ext}" |
|
else |
|
"$util" --ultra -"$l" -qc "$file" > "${file}.${l}.${ext}" |
|
fi |
|
finish=$(date +'%s%N') |
|
comp=$((${finish}-${begin})) |
|
size=$(stat -c %s "${file}.${l}.${ext}") |
|
begin=$(date +'%s%N') |
|
if [[ "$l" -lt 20 ]]; then |
|
"$util" -"$l" -qdc "${file}.${l}.${ext}" > "$file" |
|
else |
|
"$util" --ultra -"$l" -qdc "${file}.${l}.${ext}" > "$file" |
|
fi |
|
finish=$(date +'%s%N') |
|
decomp=$((${finish}-${begin})) |
|
compbps=$(echo "scale=3; 10^9*${size}/${comp}" | bc) |
|
decompbps=$(echo "scale=3; 10^9*${size}/${decomp}" | bc) |
|
if [[ "$l" -eq "$nproc" ]]; then |
|
echo "$util -$l | $compbps | $size | $decompbps | default" |
|
elif [[ "$l" -gt 19 ]]; then |
|
echo "$util --ultra -$l | $compbps | $size | $decompbps |" |
|
else |
|
echo "$util -$l | $compbps | $size | $decompbps |" |
|
fi |
|
rm "${file}.${l}.${ext}" &> /dev/random |
|
done |
|
;; |
|
xz) |
|
ext="xz" |
|
for l in {0..9}; do |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -c "$file" > "${file}.${l}.${ext}" |
|
finish=$(date +'%s%N') |
|
comp=$((${finish}-${begin})) |
|
size=$(stat -c %s "${file}.${l}.${ext}") |
|
begin=$(date +'%s%N') |
|
"$util" -"$l" -dc "${file}.${l}.${ext}" > "$file" |
|
finish=$(date +'%s%N') |
|
decomp=$((${finish}-${begin})) |
|
compbps=$(echo "scale=3; 10^9*${size}/${comp}" | bc) |
|
decompbps=$(echo "scale=3; 10^9*${size}/${decomp}" | bc) |
|
if [[ "$l" -eq 6 ]]; then |
|
echo "$util -$l | $compbps | $size | $decompbps | default" |
|
else |
|
echo "$util -$l | $compbps | $size | $decompbps |" |
|
fi |
|
rm "${file}.${l}.${ext}" &> /dev/random |
|
done |
|
for l in {0..9}; do |
|
begin=$(date +'%s%N') |
|
"$util" -e -"$l" -c "$file" > "${file}.${l}.${ext}" |
|
finish=$(date +'%s%N') |
|
comp=$((${finish}-${begin})) |
|
size=$(stat -c %s "${file}.${l}.${ext}") |
|
begin=$(date +'%s%N') |
|
"$util" -e -"$l" -dc "${file}.${l}.${ext}" > "$file" |
|
finish=$(date +'%s%N') |
|
decomp=$((${finish}-${begin})) |
|
compbps=$(echo "scale=3; 10^9*${size}/${comp}" | bc) |
|
decompbps=$(echo "scale=3; 10^9*${size}/${decomp}" | bc) |
|
echo "$util -e -$l | $compbps | $size | $decompbps |" |
|
rm "${file}.${l}.${ext}" &> /dev/random |
|
done |
|
;; |
|
zstd) |
|
ext="zst" |
|
for l in {0..22}; do |
|
begin=$(date +'%s%N') |
|
if [[ "$l" -lt 20 ]]; then |
|
"$util" -"$l" -qc "$file" > "${file}.${l}.${ext}" |
|
else |
|
"$util" --ultra -"$l" -qc "$file" > "${file}.${l}.${ext}" |
|
fi |
|
finish=$(date +'%s%N') |
|
comp=$((${finish}-${begin})) |
|
size=$(stat -c %s "${file}.${l}.${ext}") |
|
begin=$(date +'%s%N') |
|
if [[ "$l" -lt 20 ]]; then |
|
"$util" -"$l" -qdc "${file}.${l}.${ext}" > "$file" |
|
else |
|
"$util" --ultra -"$l" -qdc "${file}.${l}.${ext}" > "$file" |
|
fi |
|
finish=$(date +'%s%N') |
|
decomp=$((${finish}-${begin})) |
|
compbps=$(echo "scale=3; 10^9*${size}/${comp}" | bc) |
|
decompbps=$(echo "scale=3; 10^9*${size}/${decomp}" | bc) |
|
if [[ "$l" -eq 3 ]]; then |
|
echo "$util -$l | $compbps | $size | $decompbps | default" |
|
elif [[ "$l" -gt 19 ]]; then |
|
echo "$util --ultra -$l | $compbps | $size | $decompbps |" |
|
else |
|
echo "$util -$l | $compbps | $size | $decompbps |" |
|
fi |
|
rm "${file}.${l}.${ext}" &> /dev/random |
|
done |
|
;; |
|
esac |
|
done |