acp.sh revision 260684
11556Srgrimes#!/bin/sh
21556Srgrimes# $Id: acp.sh 2086 2011-10-27 05:18:01Z jkoshy $
31556Srgrimes
41556Srgrimes# This script is adapted from Jan Psota's Tar Comparison Program(TCP).
51556Srgrimes
61556Srgrimesn=3			# number of repetitions
71556SrgrimesAR="bsdar gnuar"	# ar archivers to compare
81556Srgrimes
91556Srgrimestest $# -ge 2 || {
101556Srgrimes    echo "usage: $0 source_dir where_to_place_archive [where_to_extract_it]"
111556Srgrimes    exit 0
121556Srgrimes}
131556Srgrimes
141556SrgrimesTHISDIR=`/bin/pwd`
151556Srgrimessrc=$1
161556Srgrimesdst=$2/acp.a
171556Srgrimesext=${3:-$2}/acptmp
181556Srgrimestest -e $dst -o -e /tmp/acp \
191556Srgrimes    && { echo "$dst or /tmp/acp exists, exiting"; exit 1; }
201556Srgrimesmkdir -p $ext || exit 1
211556Srgrimes
221556Srgrimesshow_result ()
231556Srgrimes{
241556Srgrimes    awk -vL="`du -k $dst`" '{printf "%s\t%s\t%s\%10.1d KB/s\n",
251556Srgrimes$1, $3, $5, ($1>0?L/$1:0)}' /tmp/acp | sort | head -n 1
261556Srgrimes}
271556Srgrimes
281556Srgrimestest -d $src || { echo "'$src' is not a directory"; exit 1; }
291556Srgrimes
301556Srgrimes# ar versions
311556Srgrimesfor ar in $AR; do echo -n "$ar:	"; $ar -V | head -n 1;
321556Srgrimesdone
33114301Sobrien
341556Srgrimesecho
3520412Ssteveecho "best time of $n repetitions"
361556Srgrimesecho -n "		src=$src, "
371556Srgrimesecho -n "`du -sh $src | awk '{print $1}'`"
381556Srgrimesecho -n " in "
39114301Sobrienecho "`find $src | wc -l` files"
401556Srgrimesecho "		archive=$dst, extract to $ext"
411556Srgrimes
4235772Scharnierecho "program	operation	real	user	system	   speed"
4336000Scharnierfor op in "cru $dst $src/*" "t $dst" "x `basename $dst`"; do
4435772Scharnier    for ar in $AR; do
451556Srgrimes	echo -n "$ar	"
4699109Sobrien	echo $op | grep -q ^cr && echo -n "create		"
4799109Sobrien	echo $op | grep -q ^t && echo -n "list		"
481556Srgrimes	echo $op | grep -q ^x && echo -n "extract		"
491556Srgrimes	num=0
501556Srgrimes	while [ $num -lt $n ]; do
5183482Sdillon	    echo $op | grep -q ^cr && rm -f $dst
5283482Sdillon	    echo $op | grep -q ^x && { rm -rf $ext; mkdir -p $ext
5383482Sdillon		cp $dst $ext; cd $ext; }
5483482Sdillon	    sync
5583482Sdillon	    time $ar $op > /dev/null 2>> /tmp/acp
561556Srgrimes	    echo $op | grep -q ^x && cd $THISDIR
571556Srgrimes	    num=`expr $num + 1`
581556Srgrimes	done
591556Srgrimes	show_result
6018578Sache	rm -rf /tmp/acp
611556Srgrimes    done
621556Srgrimes    echo
6378732Sdddone
641556Srgrimesrm -rf $ext $dst
6583482Sdillonrm -f /tmp/acp
661556Srgrimes