| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
set -e -o pipefail |
| 4 |
|
| 5 |
function echo_to_stderr { |
| 6 |
echo "$1" 1>&2 |
| 7 |
} |
| 8 |
|
| 9 |
function usage_and_exit { |
| 10 |
echo_to_stderr "Usage:" |
| 11 |
echo_to_stderr " $0 <path-to-js> <number-of-iterations>" |
| 12 |
echo_to_stderr |
| 13 |
echo_to_stderr "Run octane <number-of-iterations> times, and aggregate the results" |
| 14 |
echo_to_stderr "into one CSV file, which is written to stdout." |
| 15 |
echo_to_stderr |
| 16 |
echo_to_stderr "See the js/src/devtools/plot-octane.R script for plotting the" |
| 17 |
echo_to_stderr "results." |
| 18 |
echo_to_stderr |
| 19 |
echo_to_stderr "Complete example usage with plotting:" |
| 20 |
echo_to_stderr |
| 21 |
echo_to_stderr " \$ ./js/src/devtools/octane-csv.sh path/to/js 20 > control.csv" |
| 22 |
echo_to_stderr |
| 23 |
echo_to_stderr " Next, apply some patch you'd like to test." |
| 24 |
echo_to_stderr |
| 25 |
echo_to_stderr " \$ ./js/src/devtools/octane-csv.sh path/to/js 20 > variable.csv" |
| 26 |
echo_to_stderr " \$ ./js/src/devtools/plot-octane.R control.csv variable.csv" |
| 27 |
echo_to_stderr |
| 28 |
echo_to_stderr " Open Rplots.pdf to view the results." |
| 29 |
exit 1 |
| 30 |
} |
| 31 |
|
| 32 |
if [[ "$#" != "2" ]]; then |
| 33 |
usage_and_exit |
| 34 |
fi |
| 35 |
|
| 36 |
# Get the absolute, normalized $JS path, and ensure its an executable. |
| 37 |
|
| 38 |
JS_DIR=$(dirname $1) |
| 39 |
if [[ ! -d "$JS_DIR" ]]; then |
| 40 |
echo_to_stderr "error: no such directory $JS_DIR" |
| 41 |
echo_to_stderr |
| 42 |
usage_and_exit |
| 43 |
fi |
| 44 |
|
| 45 |
JS=$(basename $1) |
| 46 |
cd "$JS_DIR" > /dev/null |
| 47 |
JS="$(pwd)/$JS" |
| 48 |
if [[ ! -e "$JS" ]]; then |
| 49 |
echo_to_stderr "error: '$JS' is not executable" |
| 50 |
echo_to_stderr |
| 51 |
usage_and_exit |
| 52 |
fi |
| 53 |
cd - > /dev/null |
| 54 |
|
| 55 |
# Go to the js/src/octane directory. |
| 56 |
|
| 57 |
cd $(dirname $0)/../octane > /dev/null |
| 58 |
|
| 59 |
# Run octane and transform the results into CSV. |
| 60 |
# |
| 61 |
# Run once as a warm up, and to grab the column headers. Then run the benchmark |
| 62 |
# $ITERS times, grabbing just the data rows. |
| 63 |
|
| 64 |
echo_to_stderr "Warm up" |
| 65 |
"$JS" ./run.js | grep -v -- "----" | cut -f 1 -d ':' | tr '\n' ',' |
| 66 |
echo |
| 67 |
|
| 68 |
ITERS=$2 |
| 69 |
while [[ "$ITERS" -ge "1" ]]; do |
| 70 |
echo_to_stderr "Iterations left: $ITERS" |
| 71 |
"$JS" ./run.js | grep -v -- "----" | cut -f 2 -d ':' | tr '\n' ',' |
| 72 |
echo |
| 73 |
ITERS=$((ITERS - 1)) |
| 74 |
done |
| 75 |
|
| 76 |
echo_to_stderr "All done :)" |