/archivers/libarchive/files/contrib/psota-benchmark/tcp.sh

https://github.com/mend0za/pkgsrc-2011Q3 · Shell · 104 lines · 89 code · 10 blank · 5 comment · 17 complexity · ef3dbf54d93728ec108602e028adeac8 MD5 · raw file

  1. #!/bin/sh
  2. # tar comparision program
  3. # 2007-10-25 Jan Psota
  4. n=3 # number of repetitions
  5. TAR=(bsdtar gnutar star) # TApeArchivers to compare
  6. OPT=("" "--seek" "-no-fsync")
  7. pax="--format=pax" # comment out for defaults
  8. OPN=(create list extract compare) # operations
  9. version="2007-10-25"
  10. TIMEFORMAT=$'%R\t%U\t%S\t%P'
  11. LC_ALL=C
  12. test $# -ge 2 || {
  13. echo -e "usage:\t$0 source_dir where_to_place_archive
  14. [where_to_extract_it]
  15. TCP, version $version
  16. TCP stands for Tar Comparision Program here.
  17. It currently compares: BSD tar (bsdtar), GNU tar (gnutar) and star in archive
  18. creation, listing, extraction and archive-to-extracted comparision.
  19. Tcp prints out best time of n=$n repetitions.
  20. Tcp creates temporary archive named tcp.tar with $pax and some native
  21. (--seek/-no-fsync) options and extracts it to [\$3]/tcptmp/.
  22. If unset, third argument defaults to [\$2].
  23. After normal exit tcp removes tarball and extracted files.
  24. Tcp does not check filesystems destination directories are on for free space,
  25. so make sure there is enough space (a bit more than source_dir uses) for both:
  26. archive and extracted files.
  27. Do not use white space in arguments.
  28. Jan Psota, $version"
  29. exit 0
  30. }
  31. src=$1
  32. dst=$2/tcp.tar
  33. dst_path=${3:-$2}/tcptmp
  34. test -e $dst -o -e /tmp/tcp \
  35. && { echo "$dst or /tmp/tcp exists, exiting"; exit 1; }
  36. mkdir $dst_path || exit 2
  37. use_times ()
  38. {
  39. awk -F"\t" -vN=$n -vL="`du -k $dst`" -vOFS="\t" -vORS="" '
  40. { if (NF==4) { printf "\t%s\t%10.1d KB/s\n", $0, ($1+0>0 ?
  41. (L+0)/($1+0) : 0) } }' \
  42. /tmp/tcp | sort | head -1
  43. > /tmp/tcp
  44. }
  45. test -d $src || { echo "'$src' is not a directory"; exit 3; }
  46. # system information: type, release, memory, cpu(s), compiler and flags
  47. echo -e "TCP, version $version\n"`uname -sr`" / "`head -1 /etc/*-release`
  48. free -m | awk '/^Mem/ { printf "%dMB of memory, ", $2 }'
  49. test -e /proc/cpuinfo \
  50. && awk -F: '/name|cache size|MHz|mips/ { if (!a) b=b $2 }
  51. /^$/ { a++ } END { print a" x"b" bmips" }' /proc/cpuinfo
  52. test -e /etc/gentoo-release \
  53. && gcc --version | head -1 && grep ^CFLAGS /etc/make.conf
  54. # tar versions
  55. echo
  56. for tar in [EMAIL PROTECTED]; do echo -ne "$tar:\t"; $tar --version | head -1;
  57. done
  58. echo -e "\nbest time of $n repetitions,\n"\
  59. " src=$src, "\
  60. `du -sh $src | awk '{print $1}'`" in "`find $src | wc -l`" files, "\
  61. "avg "$((`du -sk $src | awk '{print $1}'`/`find $src -type f | wc
  62. -l`))"KB/file,\n"\
  63. " archive=$dst, extract to $dst_path"
  64. echo -e "program\toperation\treal\tuser\tsystem\t%CPU\t speed"
  65. > /tmp/tcp
  66. let op_num=0
  67. for op in "cf $dst $pax -C $src ." "tf $dst" "xf $dst -C $dst_path" \
  68. "f $dst -C $dst_path --diff"; do
  69. let tar_num=0
  70. for tar in [EMAIL PROTECTED]; do
  71. echo -en "$tar\t${OPN[op_num]}\t"
  72. for ((i=1; i<=$n; i++)); do
  73. echo $op | grep -q ^cf && rm -f $dst
  74. echo $op | grep -q ^xf &&
  75. { chmod -R u+w $dst_path
  76. rm -rf $dst_path; mkdir $dst_path; }
  77. sync
  78. if echo $op | grep -q ^f; then # op == compare
  79. time $tar $op ${OPT[$tar_num]} > /dev/null
  80. else # op in (create | list | extract)
  81. time $tar $op ${OPT[$tar_num]} > /dev/null \
  82. || break 3
  83. fi 2>> /tmp/tcp
  84. done
  85. use_times
  86. let tar_num++
  87. done
  88. let op_num++
  89. echo
  90. done
  91. rm -rf $dst_path $dst
  92. echo
  93. cat /tmp/tcp
  94. rm -f /tmp/tcp