aboutsummaryrefslogtreecommitdiff
path: root/comparison/tools/sptest_commands.sh~
blob: 0451c4e861818f2c62ca829c948c349433a01d65 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# $1: name list of commands
# ex: ./sptest_commands.sh fib38 bsort-40000


# repeat and waittimes
ct=10
waittime=5

# etc
log="log.txt"

# -------------------------------------------------
function gettime() {
  rm -f _result.txt
  for ((i=1; i<ct; i++))
  do
      (time $1) 2>> _result.txt
      echo 
      echo "Done ($i/$ct)"
      sleep $waittime
      echo 'Restart'
  done
  (time $1) 2>> _result.txt
  echo
  echo
  logtime=`grep real _result.txt | awk -F'\t' '{print $2}' | cut -c3- | awk -F's' '{print $1}'`
  echo "Execution times"
  echo "$logtime"
  res=`echo "$logtime\n" | awk 'BEGIN{r=0;c=0} {r=r+$0;c++} END{print r/c}'` 

  # for return value
  res=`grep real _result.txt | awk -F'\t' '{print $2}' | cut -c3- | awk -F's' '{print $1}' | awk 'BEGIN{r=0;c=0} {r=r+$0;c++} END{print r/c}'`
  rm -f _result.txt
}


rm -f $log

echo '' >> $log
echo "$ct" | awk -F',' '{printf("%-27s| avg. time over %d runs (sec)\n","",$1)}' >> $log
echo '===========================+=============================' >> $log

for f in "$@"; do
  command="$f"
  echo 'Now just cooling CPU...'
  sleep $waittime
  echo 'The experimental was started.'
  echo "------------------"   
  echo "$f"
  gettime "./$f"
  echo "Average ${res}sec"
  echo "$command,$res" | awk -F',' '{printf("%-27s| %.2f\n",$1,$2)}' >> $log
done

echo
cat $log