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