| 1 | #!/bin/bashscip-shell filesystem . . `/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 [scip-shell system . . `[`. ! -x /usr/bin/timescip-shell filesystem . . `/usr/bin/time`. ]; then |
| 11 | echoscip-shell system . . echo. "You need to install GNU time (http://www.gnu.org/software/time)." |
| 12 | echoscip-shell system . . echo. "$ sudo apt-get install time" |
| 13 | exit 1 |
| 14 | fi |
| 15 | if [scip-shell system . . `[`. ! -x /usr/bin/bcscip-shell filesystem . . `/usr/bin/bc`. ]; then |
| 16 | echoscip-shell system . . echo. "You need to install GNU bc (http://ftp.gnu.org/gnu/bc/)." |
| 17 | echoscip-shell system . . 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 | echoscip-shell system . . 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=$(echoscip-shell system . . echo. -n "$PAGENAME" | sedscip-shell system . . sed. -e 's/ /_/g') |
| 69 | |
| 70 | # decorate with git commit info |
| 71 | log='' |
| 72 | if [scip-shell system . . `[`. -n "$GIT_STYLE" ]; then |
| 73 | log="$(gitscip-shell system . . git. log --oneline -n 1 --no-decorate)" |
| 74 | hash=$(echoscip-shell system . . echo. "$log" | sedscip-shell system . . sed. -e 's/ .*//') |
| 75 | # count commits since GIT_HASH |
| 76 | if [scip-shell system . . `[`. -n "$GIT_HASH" ]; then |
| 77 | count=$(printfscip-shell system . . printf. '%03d' $(gitscip-shell system . . git. rev-list "$GIT_HASH"..."$hash" | wcscip-shell system . . wc. -l)) |
| 78 | OUTPUT="$OUTPUT-$count" |
| 79 | fi |
| 80 | OUTPUT="$OUTPUT-$hash" |
| 81 | fi |
| 82 | |
| 83 | # Pre-record network traffic, if necessary. |
| 84 | if [scip-shell system . . `[`. -n "$FORCE" -o ! -f $(dirnamescip-shell system . . dirname. $0)/../nocks/en.wikipedia.org/"$PAGENAME.js" ]; then |
| 85 | echoscip-shell system . . echo. "Recording parse network traffic." |
| 86 | $(dirnamescip-shell system . . dirname. $0)/../bin/parse.js --wt2html --domain en.wikipedia.org \ |
| 87 | --pageName $PAGENAME --record < /dev/nullscip-shell filesystem . . `/dev/null`. > /dev/nullscip-shell filesystem . . `/dev/null`. |
| 88 | fi |
| 89 | |
| 90 | # only re-run benchmark if output file doesn't exist. otherwise, just |
| 91 | # recompute average |
| 92 | if [scip-shell system . . `[`. -n "$FORCE" -o ! -f "$OUTPUT.times" ]; then |
| 93 | rmscip-shell system . . rm. -f "$OUTPUT.times" |
| 94 | for f in $(seqscip-shell system . . seq. 1 $REPEAT) extra1 extra2; do |
| 95 | /usr/biscip-shell system . . dirname.n/timescip-shell filesystem . . `/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/nullscip-shell filesystem . . `/dev/null`. > /dev/nullscip-shell filesystem . . `/dev/null`. |
| 98 | done |
| 99 | fi |
| 100 | |
| 101 | # now summarize |
| 102 | avg=$(echoscip-shell system . . echo. "scale=3;(" $(for f in $(sortscip-shell system . . sort. -n "$OUTPUT.times" | headscip-shell system . . head. -n-1 | tailscip-shell system . . tail. -$REPEAT) ; do echoscip-shell system . . echo. -n $f + ; done) "0)/$REPEAT" | bc) |
| 103 | |
| 104 | if [scip-shell system . . `[`. -n "$GIT_STYLE" ]; then |
| 105 | echoscip-shell system . . echo. $avg $log |
| 106 | else |
| 107 | echoscip-shell system . . echo. $avg |
| 108 | fi |