-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_compress
executable file
·90 lines (78 loc) · 2 KB
/
test_compress
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
if [[ -z "$4" ]]
then
in_dirs=(cantrbry large other)
else
in_dirs=($4)
fi
#in_dirs=( large )
if [[ $# -lt 3 ]]
then
echo "Usage: $0 compressor decompressor directory"
echo "Compressor and decompressor are programs that takes infile and outfile as parameters"
echo "Directory is the directory for the compressed files in outfiles/"
exit 0
fi
compressor="$1"
decompressor="$2"
outdir="$3"
tmpfile="tmp.tmp"
if [ ! -d "outfiles" ]; then
mkdir "outfiles"
fi
if [ ! -d "outfiles/$outdir" ]; then
mkdir "outfiles/$outdir"
fi
printf "%-35s%-30s%-20s%-17s%-15s%-15s\n" "File" "Compress and decompress" "Compression ratio" "Bits per symbol" "Orig size" "Comp size"
#For timing
s1=$(date +%s.%N)
counter=0
tot_orig_size=0
tot_comp_size=0
decomp="SUCCESS"
for dir in ${in_dirs[@]}
do
if [ ! -d "outfiles/$outdir/$dir" ]; then
mkdir "outfiles/$outdir/$dir"
fi
for i in infiles/$dir/*
do
counter=$counter+1
file=${i/*\/*\//}
infile="$i"
outfile="outfiles/$outdir/$dir/$file"
if ! $compressor $infile $outfile
then
exit 0
fi
if ! $decompressor $outfile $tmpfile
then
exit 0
fi
#echo "aa" >> $tmpfile
res=$(diff $infile $tmpfile)
if [ -z "$res" ]
then
result="SUCCESS"
else
result="FAIL"
decomp="FAIL"
fi
rm $tmpfile
comp_size=$(stat -c%s "$outfile")
orig_size=$(stat -c%s "$infile")
tot_orig_size=$(($tot_orig_size + $orig_size))
tot_comp_size=$(($tot_comp_size + $comp_size))
ratio=$(echo "scale=3;$comp_size/$orig_size" | bc)
bps=$(echo "scale=2;$ratio*8/1" | bc)
printf "%-35s%-30s%-20s%-17s%-15s%-15s\n" $infile $result $ratio $bps $orig_size $comp_size
done
done
ratio=$(echo "scale=3;$tot_comp_size/$tot_orig_size" | bc)
bps=$(echo "scale=2;$ratio*8/1" | bc)
printf "\n%-35s%-30s%-20s%-17s%-15s%-15s\n" "Total:" $decomp $ratio $bps $tot_orig_size $tot_comp_size
s2=$(date +%s.%N)
duration=$(echo "scale=2;($s2-$s1)/1" | bc)
echo
echo "Total time spent: $duration seconds"
echo