--- /dev/null
+#!/bin/bash
+
+
+function usage(){
+ echo "$0 <file.{xml, srx}>"
+
+}
+
+if [ -z "$1" -o ! -f "$1" ]
+then
+ usage
+ exit 1
+fi
+
+DOC="$1"
+
+FILENAME=`basename "$DOC"`
+FILENAME=`echo "$FILENAME" | sed -e 's/\.srx/\.xml/'`
+REFERENCE=tests/perf_tests/"$FILENAME".best
+QUERIES=tests/perf_tests/"$FILENAME".queries
+
+function cecho() {
+ case "$1" in
+ green)
+ START="\033[0;32m"
+ END="\033[0m"
+ ;;
+ yellow)
+ START="\033[1;33m"
+ END="\033[0m"
+ ;;
+ red)
+ START="\033[0;31m"
+ END="\033[0m"
+ ;;
+ *)
+ START=""
+ END=""
+ ;;
+ esac
+ echo -n -e "${START}${2}${END}"
+}
+
+function getline(){
+ FILE="$1"
+ I="$2"
+ cat "$FILE" | tail -n +"$I" | head -n 1
+}
+
+
+
+I=1
+
+while read Q
+do
+echo "Query $I"
+echo "$Q"
+REF=`getline "$REFERENCE" "$I"`
+RCOUNT=`echo "$REF" | cut -f 2 -d ,`
+RTCOUNT=`echo "$REF" | cut -f 3 -d ,`
+RTMAT=`echo "$REF" | cut -f 4 -d ,`
+
+./main.native -r 1 -d -c "$DOC" "$Q" > tmp 2>&1
+TCOUNT=`cat tmp | grep 'Execution time' | grep -o '[0-9]\+\.[0-9]*' | sort -g | head -1`
+CCOUNT=`cat tmp | grep 'Number of results' | grep -o '[0-9]\+'`
+
+./main.native -r 1 -d "$DOC" "$Q" > tmp 2>&1
+TMAT=`cat tmp | grep 'Execution time' | grep -o '[0-9]\+\.[0-9]*' | sort -g | head -1`
+MCOUNT=`cat tmp | grep 'Number of results' | grep -o '[0-9]\+'`
+
+rm -f tmp
+I=$(($I + 1))
+
+if [ "$MCOUNT" != "$CCOUNT" ]
+then
+ echo "Count mismatch between counting and materialization ! ($MCOUNT, $CCOUNT)"
+ echo
+ continue
+fi
+
+if [ "$MCOUNT" != "$RCOUNT" -a "$RCOUNT" ]
+then
+ echo "Count mismatch between current and reference implementation!"
+ echo
+ continue
+fi
+
+CSPEED=`echo '5k 1 ' "$TCOUNT" "$RTCOUNT" ' / - p' | dc`
+echo -n "Reference counting time: $RTCOUNT, Current counting time: $TCOUNT, "
+case $CSPEED in
+ -.0*)
+ cecho yellow "slow-down: $CSPEED"
+ ;;
+ -*) cecho red "slow-down: $CSPEED"
+ ;;
+ *)
+ cecho green "speed-up: $CSPEED"
+ ;;
+esac
+echo
+
+MSPEED=`echo '5k 1 ' "$TMAT" "$RTMAT" ' / - p' | dc`
+echo -n "Reference mat. time: $RTMAT, Current mat. time: $TMAT, "
+case $MSPEED in
+ -.0*)
+ cecho yellow "slow-down: $MSPEED"
+ ;;
+ -*) cecho red "slow-down: $MSPEED"
+ ;;
+ *)
+ cecho green "speed-up: $MSPEED"
+ ;;
+esac
+echo
+echo
+
+done < "$QUERIES"