occurences_grammar.sh 5.35 KB
Newer Older
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
#!/bin/bash

xslt=`grep 'xslt' benchmarks-all-full.xml | sed -e 's/.*href="\([^"]*\).*/\1/'`
xquery=`grep 'xquery' benchmarks-all-full.xml | sed -e 's/.*href="\([^"]*\).*/\1/'`

# XSLT queries (total)
total_xslt=0
for file in $xslt
do
  count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath)" $file`
  total_xslt=$(($total_xslt+$count))
done

# Xquery queries (total)
total_xquery=0
for file in $xquery
do
  count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath)" $file`
  total_xquery=$(($total_xquery+$count))
done

# Total queries
total=$(($total_xslt+$total_xquery))

printf '\\begin{tabular}{lrrr}\n'
printf '\\toprule\n'
Anthony LICK's avatar
Anthony LICK committed
27
printf 'Grammar construct & XSLT & XQuery & Total \\\\\n'
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
printf '\\midrule\n'

list=(xpathAxis rootExpr stepExpr predicates unionOp functionCallExpr varRef letExpr forExpr orOp isOp data datap)
legend=('$\\alpha\\dd$' '$/\\pi$' '$\\pi/\\pi$' '$\\pi[\\varphi]$' '$\\pi\\mathrel\\texttt{union}\\pi$' '$f(\\pi_1,\\dots,\\pi_n)$' '$\\mathtt{\\$x}$' '$\\texttt{let}\\:\\mathtt{\\$x}:=\\pi\\mathbin\\texttt{return}\\pi$' '$\\texttt{for}\\:\\mathtt{\\$x}\\mathrel\\texttt{in}\\pi\\mathrel\\texttt{return}\\pi$' '$\\varphi\\mathrel\\texttt{or}\\varphi,~\\varphi\\mathrel\\texttt{and}\\varphi$' '$\\pi\\mathrel\\texttt{is}\\pi$' '$\\pi\\mathbin\\triangle\\pi$' '$\\pi\\mathbin{\\trianglep}d$')

n=`echo ${#list[@]}`
for (( i=0; i<$n; i++))
do
  name=`echo ${list[$i]}`
  printf ${legend[$i]}
  printf ' & '
  # XSLT files
  count_xslt=0
  for file in $xslt
  do
    if [ $name = "stepExpr" ]; then
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast//xqx:stepExpr/following-sibling::*[1 and self::xqx:stepExpr]])" $file`
    elif [ $name = "forExpr" ]; then
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast[.//xqx:forExpr or .//xqx:quantifiedExpr]])" $file`
    elif [ $name = "orOp" ]; then
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast[.//xqx:orOp or .//xqx:andOp]])" $file`
    elif [ $name = "data" ]; then
Anthony LICK's avatar
Anthony LICK committed
50
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast[.//xqx:eqOp or .//xqx:neOp or .//xqx:equalOp or .//xqx:notEqualOp]])" $file`
51
    elif [ $name = "datap" ]; then
Anthony LICK's avatar
Anthony LICK committed
52
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast/descendant::*[(local-name()='eqOp' or local-name()='equalOp' or local-name()='neOp' or local-name()='notEqualOp' or local-name()='ltOp' or local-name()='leOp' or local-name()='gtOp' or local-name()='geOp' or local-name()='lessThanOp' or local-name='lessThanOrEqualOp' or local-name()='greaterThanOp' or local-name()='greaterThanOrEqualOp') and child::*[local-name()='firstOperand' or local-name()='secondOperand']/child::*[local-name()='integerConstantExpr' or local-name()='decimalConstantExpr' or local-name()='doubleConstantExpr' or local-name()='stringConstantExpr']]])" $file`
53 54 55 56 57 58 59 60 61 62 63 64
    else
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast//xqx:$name])" $file`
    fi
    count_xslt=$(($count_xslt+$count))
  done
  percent=`echo "scale=1; 100*$count_xslt/$total_xslt" | bc`
  printf $count_xslt' ('%.1f'\\%%)' $percent
  printf ' & '
  # XQuery files
  count_xquery=0
  for file in $xquery
  do
Anthony LICK's avatar
Anthony LICK committed
65 66 67
    if [ $name = "stepExpr" ]; then
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast//xqx:stepExpr/following-sibling::*[1 and self::xqx:stepExpr]])" $file`
    elif [ $name = "forExpr" ]; then
68
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast[.//xqx:forExpr or .//xqx:quantifiedExpr]])" $file`
Anthony LICK's avatar
Anthony LICK committed
69 70 71 72 73 74
    elif [ $name = "orOp" ]; then
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast[.//xqx:orOp or .//xqx:andOp]])" $file`
    elif [ $name = "data" ]; then
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast[.//xqx:eqOp or .//xqx:neOp or .//xqx:equalOp or .//xqx:notEqualOp]])" $file`
    elif [ $name = "datap" ]; then
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast/descendant::*[(local-name()='eqOp' or local-name()='equalOp' or local-name()='neOp' or local-name()='notEqualOp' or local-name()='ltOp' or local-name()='leOp' or local-name()='gtOp' or local-name()='geOp' or local-name()='lessThanOp' or local-name='lessThanOrEqualOp' or local-name()='greaterThanOp' or local-name()='greaterThanOrEqualOp') and child::*[local-name()='firstOperand' or local-name()='secondOperand']/child::*[local-name()='integerConstantExpr' or local-name()='decimalConstantExpr' or local-name()='doubleConstantExpr' or local-name()='stringConstantExpr']]])" $file`
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
    else
      count=`xmlstarlet sel -N xqx="http://www.w3.org/2005/XQueryX" -t -c "count(/benchmark/xpath[ast//xqx:$name])" $file`
    fi
    count_xquery=$(($count_xquery+$count))
  done
  percent=`echo "scale=1; 100*$count_xquery/$total_xquery" | bc`
  printf $count_xquery' ('%.1f'\\%%)' $percent
  printf ' & '
  count_total=$(($count_xslt+$count_xquery))
  percent=`echo "scale=1; 100*$count_total/$total" | bc`
  printf $count_total' ('%.1f'\\%%)' $percent
  printf ' \\\\\n'
done
printf '\\bottomrule\n'
printf '\\end{tabular}\n'