xref: /freebsd/contrib/elftoolchain/ar/benchmark/acp.sh (revision 7877fdebeeb35fad1cbbafce22598b1bdf97c786)
1#!/bin/sh
2# $Id: acp.sh 2086 2011-10-27 05:18:01Z jkoshy $
3
4# This script is adapted from Jan Psota's Tar Comparison Program(TCP).
5
6n=3			# number of repetitions
7AR="bsdar gnuar"	# ar archivers to compare
8
9test $# -ge 2 || {
10    echo "usage: $0 source_dir where_to_place_archive [where_to_extract_it]"
11    exit 0
12}
13
14THISDIR=`/bin/pwd`
15src=$1
16dst=$2/acp.a
17ext=${3:-$2}/acptmp
18test -e $dst -o -e /tmp/acp \
19    && { echo "$dst or /tmp/acp exists, exiting"; exit 1; }
20mkdir -p $ext || exit 1
21
22show_result ()
23{
24    awk -vL="`du -k $dst`" '{printf "%s\t%s\t%s\%10.1d KB/s\n",
25$1, $3, $5, ($1>0?L/$1:0)}' /tmp/acp | sort | head -n 1
26}
27
28test -d $src || { echo "'$src' is not a directory"; exit 1; }
29
30# ar versions
31for ar in $AR; do echo -n "$ar:	"; $ar -V | head -n 1;
32done
33
34echo
35echo "best time of $n repetitions"
36echo -n "		src=$src, "
37echo -n "`du -sh $src | awk '{print $1}'`"
38echo -n " in "
39echo "`find $src | wc -l` files"
40echo "		archive=$dst, extract to $ext"
41
42echo "program	operation	real	user	system	   speed"
43for op in "cru $dst $src/*" "t $dst" "x `basename $dst`"; do
44    for ar in $AR; do
45	echo -n "$ar	"
46	echo $op | grep -q ^cr && echo -n "create		"
47	echo $op | grep -q ^t && echo -n "list		"
48	echo $op | grep -q ^x && echo -n "extract		"
49	num=0
50	while [ $num -lt $n ]; do
51	    echo $op | grep -q ^cr && rm -f $dst
52	    echo $op | grep -q ^x && { rm -rf $ext; mkdir -p $ext
53		cp $dst $ext; cd $ext; }
54	    sync
55	    time $ar $op > /dev/null 2>> /tmp/acp
56	    echo $op | grep -q ^x && cd $THISDIR
57	    num=`expr $num + 1`
58	done
59	show_result
60	rm -rf /tmp/acp
61    done
62    echo
63done
64rm -rf $ext $dst
65rm -f /tmp/acp
66