Add performance regression test script.
[SXSI/xpathcomp.git] / tests / scripts / check_perf.sh
1 #!/bin/bash
2
3
4 function usage(){
5     echo "$0 <file.{xml, srx}>"
6
7 }
8
9 if [ -z "$1" -o ! -f "$1" ]
10 then
11     usage
12     exit 1
13 fi
14
15 DOC="$1"
16
17 FILENAME=`basename "$DOC"`
18 FILENAME=`echo "$FILENAME" | sed -e 's/\.srx/\.xml/'`
19 REFERENCE=tests/perf_tests/"$FILENAME".best
20 QUERIES=tests/perf_tests/"$FILENAME".queries
21
22 function cecho() {
23   case "$1" in
24       green)
25           START="\033[0;32m"
26           END="\033[0m"
27           ;;
28       yellow)
29           START="\033[1;33m"
30           END="\033[0m"
31           ;;
32       red)
33           START="\033[0;31m"
34           END="\033[0m"
35           ;;
36       *)
37           START=""
38           END=""
39           ;;
40   esac
41   echo -n -e "${START}${2}${END}"
42 }
43
44 function getline(){
45     FILE="$1"
46     I="$2"
47     cat "$FILE" | tail -n +"$I" | head -n 1
48 }
49
50
51
52 I=1
53
54 while read Q
55 do
56 echo "Query $I"
57 echo "$Q"
58 REF=`getline "$REFERENCE" "$I"`
59 RCOUNT=`echo "$REF" | cut -f 2 -d ,`
60 RTCOUNT=`echo "$REF" | cut -f 3 -d ,`
61 RTMAT=`echo "$REF" | cut -f 4 -d ,`
62
63 ./main.native -r 1 -d -c "$DOC" "$Q" > tmp 2>&1
64 TCOUNT=`cat tmp | grep 'Execution time' | grep -o '[0-9]\+\.[0-9]*' | sort -g | head -1`
65 CCOUNT=`cat tmp | grep 'Number of results' | grep -o '[0-9]\+'`
66
67 ./main.native -r 1 -d "$DOC" "$Q" > tmp 2>&1
68 TMAT=`cat tmp | grep 'Execution time' | grep -o '[0-9]\+\.[0-9]*' | sort -g | head -1`
69 MCOUNT=`cat tmp | grep 'Number of results' | grep -o '[0-9]\+'`
70
71 rm -f tmp
72 I=$(($I + 1))
73
74 if [ "$MCOUNT" != "$CCOUNT" ]
75 then
76     echo "Count mismatch between counting and materialization ! ($MCOUNT, $CCOUNT)"
77     echo
78     continue
79 fi
80
81 if [ "$MCOUNT" != "$RCOUNT" -a "$RCOUNT" ]
82 then
83     echo "Count mismatch between current and reference implementation!"
84     echo
85     continue
86 fi
87
88 CSPEED=`echo '5k 1 '  "$TCOUNT" "$RTCOUNT" ' / - p' | dc`
89 echo -n "Reference counting time: $RTCOUNT, Current counting time: $TCOUNT, "
90 case $CSPEED in
91     -.0*)
92         cecho yellow "slow-down: $CSPEED"
93         ;;
94     -*) cecho red "slow-down: $CSPEED"
95         ;;
96     *)
97         cecho green "speed-up: $CSPEED"
98         ;;
99 esac
100 echo
101
102 MSPEED=`echo '5k 1 ' "$TMAT" "$RTMAT"  ' / - p' | dc`
103 echo -n "Reference mat. time: $RTMAT, Current mat. time: $TMAT, "
104 case $MSPEED in
105     -.0*)
106         cecho yellow "slow-down: $MSPEED"
107         ;;
108     -*) cecho red "slow-down: $MSPEED"
109         ;;
110     *)
111         cecho green "speed-up: $MSPEED"
112         ;;
113 esac
114 echo
115 echo
116
117 done < "$QUERIES"