|
| 1 | +#!/bin/sh -e |
| 2 | + |
| 3 | +# manual simple benchmark tool |
| 4 | +# |
| 5 | +# env options: |
| 6 | +# TESTS - tests to run, defaults to benchmark manifest |
| 7 | +# RESULTS_DIR - base results dir, defaults to ./benchmarks/results/NAME |
| 8 | +# COMPAREJS - location of jsonld.js compare tool |
| 9 | +# ASYNC/SYNC/WEBCRYPTO - default to only ASYNC |
| 10 | +# |
| 11 | +# Usage: |
| 12 | +# $ ./benchmark/b bench NAME SEQ LABEL |
| 13 | +# $ ./benchmark/b report NAME |
| 14 | +# |
| 15 | +# Example from top dir to run 3 tests, store in my-test dir, and report: |
| 16 | +# $ ./benchmark/b bench my-test 001 'base' |
| 17 | +# $ ./benchmark/b bench my-test 002 'new feature' |
| 18 | +# $ ./benchmark/b bench my-test 003 'optimized feature' |
| 19 | +# $ ./benchmark/b report my-test |
| 20 | +# |
| 21 | +# Above will run 3 tests, store in 'my-test' dir, and run a report. |
| 22 | + |
| 23 | +DIRNAME="$(dirname "$0")" |
| 24 | +ROOT="$(cd "$DIRNAME" && pwd)" |
| 25 | + |
| 26 | +CMD="$1" |
| 27 | +NAME="$2" |
| 28 | +SEQ="$3" |
| 29 | +LABEL="$4" |
| 30 | + |
| 31 | +TESTS=${TESTS:-$ROOT} |
| 32 | +RESULTS_DIR=${RESULTS_DIR:-"$ROOT/results/$NAME"} |
| 33 | +COMPAREJS=${COMPAREJS:-"$ROOT/../../jsonld.js/benchmarks/compare/compare.js"} |
| 34 | + |
| 35 | +ASYNC=${ASYNC:-true} |
| 36 | +export ASYNC |
| 37 | +SYNC=${SYNC:-false} |
| 38 | +export SYNC |
| 39 | +WEBCRYPTO=${WEBCRYPTO:-false} |
| 40 | +export WEBCRYPTO |
| 41 | + |
| 42 | +setup() { |
| 43 | + mkdir -p "${RESULTS_DIR}" |
| 44 | +} |
| 45 | + |
| 46 | +bench() { |
| 47 | + TESTS="$ROOT" \ |
| 48 | + BENCHMARK="true" \ |
| 49 | + EARL="${RESULTS_DIR}/$SEQ.earl" \ |
| 50 | + TEST_ENV="auto,label='$LABEL',comment='$NAME'" \ |
| 51 | + npm run test-node |
| 52 | +} |
| 53 | + |
| 54 | +report() { |
| 55 | + echo "# $NAME" |
| 56 | + echo |
| 57 | + node "$COMPAREJS" -r -e combined "$RESULTS_DIR"/*.earl |
| 58 | +} |
| 59 | + |
| 60 | +case $CMD in |
| 61 | + bench) |
| 62 | + setup |
| 63 | + bench |
| 64 | + ;; |
| 65 | + report) |
| 66 | + report |
| 67 | + ;; |
| 68 | + *) echo "ERROR: Unknown command $CMD" |
| 69 | + exit 1 |
| 70 | + ;; |
| 71 | +esac |
0 commit comments