time-test.sh 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #!/usr/bin/env bash
  2. myname="${0##*/}"
  3. output=time-test.log
  4. if [[ $# == 0 ]]
  5. then
  6. cat <<- ---EOT---
  7. $myname : Test adding and extracting times of tools 'wbfs' and 'wwt'
  8. This script expect as parameters names of ISO files. These files are subject
  9. of timing tests with a temporary WBFS file.
  10. The WDF test does the following:
  11. 1.) Adding and extracting the ISO with WBFS.
  12. 2.) Adding and extracting the ISO with WWT.
  13. 3.) Adding and extracting a WDF with WWT.
  14. 4.) Extracting an ISO and a WDF with WWT --fast.
  15. The results (time in milliseconds) are written to stdout and *appended* to
  16. the end of the file '$output'.
  17. The temporary files are written to a temporary subdirectory of the current
  18. working directory (hoping that here is enough space). The directory will be
  19. is deleted at the end. The signals INT, TERM and HUP are handled.
  20. ---EOT---
  21. echo "usage: $myname iso_file" >&2
  22. echo
  23. exit 1
  24. fi
  25. #------------------------------------------------------------------------------
  26. err=
  27. for tool in wbfs wwt
  28. do
  29. which $tool >/dev/null 2>&1 || err="$err $tool"
  30. done
  31. if [[ $err != "" ]]
  32. then
  33. echo "$myname: missing tools in PATH:$err" >&2
  34. exit 2
  35. fi
  36. #------------------------------------------------------------------------------
  37. let BASE_SEC=$(date +%s)
  38. function get-msec()
  39. {
  40. echo $(($(date "+(%s-BASE_SEC)*1000+10#%N/1000000")))
  41. }
  42. #------------------------------------------------------------------------------
  43. function f_abort()
  44. {
  45. {
  46. msg="### ${myname} CANCELED ###"
  47. sep="############################"
  48. sep="$sep$sep$sep$sep"
  49. sep="${sep:1:${#msg}}"
  50. echo ""
  51. echo "$sep"
  52. echo "$msg"
  53. echo "$sep"
  54. echo ""
  55. echo "remove tempdir: $tempdir"
  56. rm -rf "$tempdir"
  57. echo ""
  58. } >&2
  59. exit 2
  60. }
  61. #------------------------------------------------------------------------------
  62. # setup
  63. tempdir=
  64. trap f_abort INT TERM HUP
  65. tempdir="$(mktemp -d ./.${myname}.tmp.XXXXXX)" || exit 1
  66. wbfs_file=a.wbfs
  67. wbfs="$tempdir/$wbfs_file"
  68. #------------------------------------------------------------------------------
  69. # tests
  70. cat <<- ---EOT--- | tee -a $output
  71. WWT WWT WWT WWT WWT WWT
  72. WBFS WBFS add ex ex -F add ex ex -F
  73. add ex ISO ISO ISO WDF WDF WDF file
  74. ----------------------------------------------------------------------------------------
  75. ---EOT---
  76. while (($#))
  77. do
  78. file="$1"
  79. id6="$(dd if="$file" bs=1 count=6)"
  80. shift
  81. echo -e "\n---------- WBFS add ----------\n"
  82. wwt init "$wbfs" -f -s10
  83. sleep 5
  84. start=$(get-msec)
  85. wbfs -p "$wbfs" add $file
  86. let t_wb_ad=$(get-msec)-start
  87. echo -e "\n---------- WBFS extract ----------\n"
  88. sleep 5
  89. start=$(get-msec)
  90. ( cd "$tempdir"; wbfs -p "$wbfs_file" extract $id6)
  91. let t_wb_ex=$(get-msec)-start
  92. rm -f "$tempdir"/*.iso
  93. echo -e "\n---------- WWT add iso ----------\n"
  94. wwt init "$wbfs" -f -s10
  95. sleep 5
  96. start=$(get-msec)
  97. wwt -p "$wbfs" add "$file"
  98. let t_wwt_ad_iso=$(get-msec)-start
  99. echo -e "\n---------- WWT ectract iso ----------\n"
  100. sleep 5
  101. start=$(get-msec)
  102. wwt -p "$wbfs" ex -d "$tempdir" $id6 -I
  103. let t_wwt_ex_iso=$(get-msec)-start
  104. rm -f "$tempdir"/*.iso
  105. echo -e "\n---------- WWT ectract iso --fast ----------\n"
  106. sleep 5
  107. start=$(get-msec)
  108. wwt -p "$wbfs" ex -d "$tempdir" $id6 -I --fast
  109. let t_wwt_ex_iso_fast=$(get-msec)-start
  110. rm -f "$tempdir"/*.iso
  111. echo -e "\n---------- WWT ectract wdf --fast ----------\n"
  112. sleep 5
  113. start=$(get-msec)
  114. wwt -p "$wbfs" ex -d "$tempdir" $id6 -W --fast
  115. let t_wwt_ex_wdf_fast=$(get-msec)-start
  116. rm -f "$tempdir"/*.wdf
  117. echo -e "\n---------- WWT ectract wdf ----------\n"
  118. sleep 5
  119. start=$(get-msec)
  120. wwt -p "$wbfs" ex -d "$tempdir" $id6=a.wdf -W
  121. let t_wwt_ex_wdf=$(get-msec)-start
  122. echo -e "\n---------- WWT add wdf ----------\n"
  123. wwt init "$wbfs" -f -s10
  124. sleep 5
  125. start=$(get-msec)
  126. wwt -p "$wbfs" add "$tempdir/a.wdf"
  127. let t_wwt_ad_wdf=$(get-msec)-start
  128. rm -f "$tempdir"/*.wdf
  129. echo -e "\n---------- output ----------\n"
  130. printf "%6d\t%6d\t%6d\t%6d\t%6d\t%6d\t%6d\t%6d\t%s\n" \
  131. $t_wb_ad $t_wb_ex \
  132. $t_wwt_ad_iso $t_wwt_ex_iso $t_wwt_ex_iso_fast \
  133. $t_wwt_ad_wdf $t_wwt_ex_wdf $t_wwt_ex_wdf_fast \
  134. "$file" | tee -a $output
  135. done
  136. #------------------------------------------------------------------------------
  137. rm -rf "$tempdir"
  138. exit 0