| 1 | #!/bin/bash |
| 2 | REPEAT=10 |
| 3 | GIT_STYLE= |
| 4 | GIT_HASH= |
| 5 | FORCE= |
| 6 | OUTPUT="wt2html-time" |
| 7 | PAGENAME="Barack Obama" |
| 8 | |
| 9 | # check dependencies |
| 10 | if [ ! -x /usr/bin/time ]; then |
| 11 | echo "You need to install GNU time (http://www.gnu.org/software/time)." |
| 12 | echo "$ sudo apt-get install time" |
| 13 | exit 1 |
| 14 | fi |
| 15 | if [ ! -x /usr/bin/bc ]; then |
| 16 | echo "You need to install GNU bc (http://ftp.gnu.org/gnu/bc/)." |
| 17 | echo "$ sudo apt-get install bc" |
| 18 | exit 1 |
| 19 | fi |
| 20 | |
| 21 | # parse options |
| 22 | while [[ "$#" -gt 0 ]]; do |
| 23 | key="$1" |
| 24 | case "$key" in |
| 25 | -f|--force) |
| 26 | FORCE=1 |
| 27 | ;; |
| 28 | -g|--git) |
| 29 | GIT_STYLE=1 |
| 30 | ;; |
| 31 | -g=*|--git=*) |
| 32 | GIT_STYLE=1 |
| 33 | GIT_HASH="${key#*=}" |
| 34 | ;; |
| 35 | -n|--repeat) |
| 36 | shift |
| 37 | REPEAT="$1" |
| 38 | ;; |
| 39 | -n=*|--repeat=*) |
| 40 | REPEAT="${key#*=}" |
| 41 | ;; |
| 42 | -o) |
| 43 | shift |
| 44 | OUTPUT="$1" |
| 45 | ;; |
| 46 | -o=*|--output=*) |
| 47 | OUTPUT="${key#*=}" |
| 48 | ;; |
| 49 | -p) |
| 50 | shift |
| 51 | PAGENAME="$1" |
| 52 | ;; |
| 53 | -p=*|--page=*) |
| 54 | PAGENAME="${key#*=}" |
| 55 | ;; |
| 56 | -*) |
| 57 | echo "Unknown option: $1" >&2 |
| 58 | exit 1 |
| 59 | ;; |
| 60 | *) |
| 61 | OUTPUT="$key" |
| 62 | ;; |
| 63 | esac |
| 64 | shift # Shift to get the next option |
| 65 | done |
| 66 | |
| 67 | # page name should have spaces replaced with underscores |
| 68 | PAGENAME=$(echo -n "$PAGENAME" | sed -e 's/ /_/g') |
| 69 | |
| 70 | # decorate with git commit info |
| 71 | log='' |
| 72 | if [ -n "$GIT_STYLE" ]; then |
| 73 | log="$(git log --oneline -n 1 --no-decorate)" |
| 74 | hash=$(echo "$log" | sed -e 's/ .*//') |
| 75 | # count commits since GIT_HASH |
| 76 | if [ -n "$GIT_HASH" ]; then |
| 77 | count=$(printf '%03d' $(git rev-list "$GIT_HASH"..."$hash" | wc -l)) |
| 78 | OUTPUT="$OUTPUT-$count" |
| 79 | fi |
| 80 | OUTPUT="$OUTPUT-$hash" |
| 81 | fi |
| 82 | |
| 83 | # Pre-record network traffic, if necessary. |
| 84 | if [ -n "$FORCE" -o ! -f $(dirname $0)/../nocks/en.wikipedia.org/"$PAGENAME.js" ]; then |
| 85 | echo "Recording parse network traffic." |
| 86 | $(dirname $0)/../bin/parse.js --wt2html --domain en.wikipedia.org \ |
| 87 | --pageName $PAGENAME --record < /dev/null > /dev/null |
| 88 | fi |
| 89 | |
| 90 | # only re-run benchmark if output file doesn't exist. otherwise, just |
| 91 | # recompute average |
| 92 | if [ -n "$FORCE" -o ! -f "$OUTPUT.times" ]; then |
| 93 | rm -f "$OUTPUT.times" |
| 94 | for f in $(seq 1 $REPEAT) extra1 extra2; do |
| 95 | /usr/bin/time -f%U -o "$OUTPUT.times" -a \ |
| 96 | $(dirname $0)/../bin/parse.js --wt2html --domain en.wikipedia.org \ |
| 97 | --pageName $PAGENAME --replay < /dev/null > /dev/null |
| 98 | done |
| 99 | fi |
| 100 | |
| 101 | # now summarize |
| 102 | avg=$(echo "scale=3;(" $(for f in $(sort -n "$OUTPUT.times" | head -n-1 | tail -$REPEAT) ; do echo -n $f + ; done) "0)/$REPEAT" | bc) |
| 103 | |
| 104 | if [ -n "$GIT_STYLE" ]; then |
| 105 | echo $avg $log |
| 106 | else |
| 107 | echo $avg |
| 108 | fi |