langsmoke/langsmoke

50 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# Get input argument
if [ $# -ne 1 ]; then
echo "Usage: langsmoke <file>"
exit 1
fi
if [ ! -r $1 ] || [ -d $1 ]; then
echo "Error: $1 is not a readable file"
exit 1
fi
# Get size of input in MB
size=$(du -sm $1 | cut -f1)
let "size++"
src=$1
bz3=$(bzip3 -fc $1 | wc -c)
lz4=$(lz4 -1c $1 2>/dev/null | wc -c)
max=$(du ref_* | sort -nr | head -n 1 | cut -f-1)
min=$(du ref_* | sort -n | head -n 1 | cut -f-1)
abs=$(python3 -c "print(abs($max-$min))")
function do_stat {
# 20MB cutoff.
ss=$(du ref_$1 | cut -f-1)
bz_stat=$(cat ref_$1 $src | head -c 20000000 | bzip3 -cefb $size | wc -c)
bz_ref=$(cat ref_$1 | bzip3 | wc -c)
bz_sim=$(python3 -c "print(100*($bz_stat - min($bz_ref, $bz3)) / (max($bz_ref, $bz3)))")
lz_stat=$(cat ref_$1 $src | head -c 20000000 | lz4 -1c | wc -c)
lz_ref=$(cat ref_$1 | lz4 -1c | wc -c)
lz_sim=$(python3 -c "print(100*($lz_stat - min($lz_ref, $lz4)) / (max($lz_ref, $lz4)))")
echo "BZ3: $bz_sim, LZ4: $lz_sim"
}
echo "C: $(do_stat c)"
echo "C++: $(do_stat cpp)"
echo "Java: $(do_stat java)"
echo "6502: $(do_stat 6502)"
echo "Z80: $(do_stat z80)"
echo "APL: $(do_stat apl)"
echo "x86: $(do_stat x86)"
echo "x64: $(do_stat x64)"
echo "Shell: $(do_stat sh)"