summaryrefslogtreecommitdiff
path: root/contrib/psota-benchmark/tcp.sh
blob: 3f630732be7cfbb12bd2e16f77cd9034ae8bfc11 (plain)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/sh
# tar comparison program
# 2007-10-25 Jan Psota

n=3                                     # number of repetitions
TAR="bsdtar gnutar star"                # Tape archivers to compare
OPT=("" "--seek" "-no-fsync")
pax="--format=pax"                      # comment out for defaults
OPN=(create list extract compare)       # operations
version="2007-10-25"
TIMEFORMAT=$'%R\t%U\t%S\t%P'
LC_ALL=C

test $# -ge 2 || {
        echo -e "usage:\t$0 source_dir where_to_place_archive 
[where_to_extract_it]

TCP, version $version
TCP stands for Tar Comparison Program here.
It currently compares: BSD tar (bsdtar), GNU tar (gnutar) and star in archive
creation, listing, extraction and archive-to-extracted comparison.
Tcp prints out best time of n=$n repetitions.

Tcp creates temporary archive named tcp.tar with $pax and some native
(--seek/-no-fsync) options and extracts it to [\$3]/tcptmp/.
If unset, third argument defaults to [\$2].
After normal exit tcp removes tarball and extracted files.
Tcp does not check filesystems destination directories are on for free space,
so make sure there is enough space (a bit more than source_dir uses) for both:
archive and extracted files.
Do not use white space in arguments.
        Jan Psota, $version"
        exit 0
}
src=$1
dst=$2/tcp.tar
dst_path=${3:-$2}/tcptmp
test -e $dst -o -e /tmp/tcp \
        && { echo "$dst or /tmp/tcp exists, exiting"; exit 1; }
mkdir $dst_path || exit 2

use_times ()
{
        awk -F"\t" -vN=$n -vL="`du -k $dst`" -vOFS="\t" -vORS="" '
                { if (NF==4) { printf "\t%s\t%10.1d KB/s\n", $0, ($1+0>0 ? 
(L+0)/($1+0) : 0) } }' \
                /tmp/tcp | sort | head -1
        > /tmp/tcp
}

test -d $src || { echo "'$src' is not a directory"; exit 3; }

# system information: type, release, memory, cpu(s), compiler and flags
echo -e "TCP, version $version\n"`uname -sr`" / "`head -1 /etc/*-release`
free -m | awk '/^Mem/ { printf "%dMB of memory, ", $2 }'
test -e /proc/cpuinfo \
        && awk -F: '/name|cache size|MHz|mips/ { if (!a) b=b $2 }
        /^$/ { a++ } END { print a" x"b" bmips" }' /proc/cpuinfo
test -e /etc/gentoo-release \
        && gcc --version | head -1 && grep ^CFLAGS /etc/make.conf

# tar versions
t=
echo
for tar in $TAR; do 
	if which $tar &> /dev/null; then
		t="$t $tar";
		echo -ne "$tar:\t"; $tar --version | head -1; 
	fi
done

TAR="$t"

echo -e "\nbest time of $n repetitions,\n"\
"       src=$src, "\
`du -sh $src | awk '{print $1}'`" in "`find $src | wc -l`" files, "\
"avg "$((`du -sk $src | awk '{print $1}'`/`find $src -type f | wc -l`))"KB/file,\n"\
"       archive=$dst, extract to $dst_path"

echo -e "program\toperation\treal\tuser\tsystem\t%CPU\t     speed"
> /tmp/tcp
let op_num=0
for op in "cf $dst $pax -C $src ." "tf $dst" "xf $dst -C $dst_path" \
        "f $dst -C $dst_path --diff"; do
        let tar_num=0
        for tar in $TAR; do
                echo -en "$tar\t${OPN[op_num]}\t"
                for ((i=1; i<=$n; i++)); do
                        echo $op | grep -q ^cf && rm -f $dst
                        echo $op | grep -q ^xf &&
                                { chmod -R u+w $dst_path
                                rm -rf $dst_path; mkdir $dst_path; }
                        sync
                        if echo $op | grep -q ^f; then  # op == compare
                                time $tar $op ${OPT[$tar_num]} > /dev/null
                        else    # op in (create | list | extract)
                                time $tar $op ${OPT[$tar_num]} > /dev/null \
                                        || break 3
                        fi 2>> /tmp/tcp
                done
                use_times
                let tar_num++
        done
        let op_num++
        echo
done
rm -rf $dst_path $dst
echo
cat /tmp/tcp
rm -f /tmp/tcp