Path: blob/main/contrib/elftoolchain/ar/benchmark/acp.sh
39536 views
#!/bin/sh1# $Id: acp.sh 2086 2011-10-27 05:18:01Z jkoshy $23# This script is adapted from Jan Psota's Tar Comparison Program(TCP).45n=3 # number of repetitions6AR="bsdar gnuar" # ar archivers to compare78test $# -ge 2 || {9echo "usage: $0 source_dir where_to_place_archive [where_to_extract_it]"10exit 011}1213THISDIR=`/bin/pwd`14src=$115dst=$2/acp.a16ext=${3:-$2}/acptmp17test -e $dst -o -e /tmp/acp \18&& { echo "$dst or /tmp/acp exists, exiting"; exit 1; }19mkdir -p $ext || exit 12021show_result ()22{23awk -vL="`du -k $dst`" '{printf "%s\t%s\t%s\%10.1d KB/s\n",24$1, $3, $5, ($1>0?L/$1:0)}' /tmp/acp | sort | head -n 125}2627test -d $src || { echo "'$src' is not a directory"; exit 1; }2829# ar versions30for ar in $AR; do echo -n "$ar: "; $ar -V | head -n 1;31done3233echo34echo "best time of $n repetitions"35echo -n " src=$src, "36echo -n "`du -sh $src | awk '{print $1}'`"37echo -n " in "38echo "`find $src | wc -l` files"39echo " archive=$dst, extract to $ext"4041echo "program operation real user system speed"42for op in "cru $dst $src/*" "t $dst" "x `basename $dst`"; do43for ar in $AR; do44echo -n "$ar "45echo $op | grep -q ^cr && echo -n "create "46echo $op | grep -q ^t && echo -n "list "47echo $op | grep -q ^x && echo -n "extract "48num=049while [ $num -lt $n ]; do50echo $op | grep -q ^cr && rm -f $dst51echo $op | grep -q ^x && { rm -rf $ext; mkdir -p $ext52cp $dst $ext; cd $ext; }53sync54time $ar $op > /dev/null 2>> /tmp/acp55echo $op | grep -q ^x && cd $THISDIR56num=`expr $num + 1`57done58show_result59rm -rf /tmp/acp60done61echo62done63rm -rf $ext $dst64rm -f /tmp/acp656667