Last active
January 11, 2022 11:51
-
-
Save kou1okada/3ef78db2426cf8cd70208b2084eb77a0 to your computer and use it in GitHub Desktop.
decompression_benchmark.sh - Decompression Benchmark
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
#!/usr/bin/env bash | |
if (( $# != 2 )); then | |
cat <<-EOD | |
Usage: ${0##*/} <count> <file> | |
Decompression benchmark | |
EOD | |
exit | |
fi | |
if ! let n="$1"; then | |
echo "Error: can't parse count: $1" | |
exit 1 | |
fi | |
ext=".${2##*.}" | |
if [ "$2" = "$ext" ]; then | |
echo "Error: can not detect filename extension: $2" | |
exit 1 | |
fi | |
file="$2" | |
case "$ext" in | |
.gz) dec=( gzip -dc );; | |
.bz2) dec=( bzip2 -dc );; | |
.xz) dec=( xz -dc );; | |
.zst) dec=( zstd -dc );; | |
*) | |
echo "Error: unsupported compression format: $ext" | |
exit 1 | |
;; | |
esac | |
let size=$(stat -c %s "$file") | |
ls -l --time-style="+%F %T" "$file" | |
{ | |
time for i in $(seq 1 $n); do | |
"${dec[@]}" "$file" >/dev/null | |
done | |
} |& gawk -vn=$n -vsize=$size ' | |
function tosec(s) {return match(s, /([0-9]+)m([.0-9]+)s/,m) ? m[1]*60+m[2] : 0} | |
/^(real|user|sys)/ {$2=tosec($2); mb = size * n / 1000000.0; printf("\t%-4s %5.1fMB, %6.3fs, %6.1fMB/s, %6.3fs/MB\n", $1, mb, $2, mb / $2, $2 / mb);} | |
' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment