Skip to content

Commit f29085d

Browse files
committed
Add benchmark scripts.
1 parent be18fd7 commit f29085d

File tree

2 files changed

+135
-0
lines changed

2 files changed

+135
-0
lines changed

benchmark/b-a-s-wc

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/sh -e
2+
3+
# platform: node only
4+
# test: async vs sync vs webcrypto
5+
6+
DIRNAME="$(dirname "$0")"
7+
ROOT="$(cd "$DIRNAME" && pwd)"
8+
9+
TIMESTAMP=$(date +%Y%m%dT%H%M%S)
10+
NAME="async-v-sync-v-webcrypto"
11+
12+
COMPAREJS=${COMPAREJS:-"$ROOT/../../jsonld.js/benchmarks/compare/compare.js"}
13+
RESULTS_DIR=${RESULTS_DIR:-"$ROOT/results/$TIMESTAMP-$NAME"}
14+
15+
setup() {
16+
mkdir -p "${RESULTS_DIR}"
17+
}
18+
19+
bench_mode() {
20+
n=$1
21+
mode=$2
22+
jobs=$3
23+
24+
echo "BENCH: n=$n mode=$mode jobs=$jobs"
25+
26+
TESTS="$ROOT" \
27+
BENCHMARK="jobs=$jobs" \
28+
EARL="${RESULTS_DIR}/$n-$mode-$jobs.earl" \
29+
TEST_ENV="auto,label='$mode',comment='jobs=$jobs'" \
30+
npm run test-node
31+
}
32+
33+
bench() {
34+
jobs=1
35+
ASYNC=1 SYNC=0 WEBCRYPTO=0 bench_mode 001 async "$jobs"
36+
ASYNC=0 SYNC=1 WEBCRYPTO=0 bench_mode 002 sync "$jobs"
37+
ASYNC=0 SYNC=0 WEBCRYPTO=1 bench_mode 003 webcrypto "$jobs"
38+
}
39+
40+
report() {
41+
dir=${1:-$RESULTS_DIR}
42+
43+
echo "# async vs sync vs webcrypto"
44+
echo
45+
node "$COMPAREJS" -r -e combined "$dir"/*.earl
46+
}
47+
48+
if [ "$1" = "report" ]; then
49+
if [ "$2" = "" ]; then
50+
echo "Error: report dir required."
51+
exit 1
52+
fi
53+
report "$2"
54+
exit 0
55+
fi
56+
57+
setup
58+
bench
59+
report

benchmark/b-jobs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/sh -e
2+
3+
# platform: node only
4+
# test: async vs sync vs webcrypto with different job sizes
5+
#
6+
DIRNAME="$(dirname "$0")"
7+
ROOT="$(cd "$DIRNAME" && pwd)"
8+
9+
TIMESTAMP=$(date +%Y%m%dT%H%M%S)
10+
NAME="jobs"
11+
12+
COMPAREJS=${COMPAREJS:-"$ROOT/../../jsonld.js/benchmarks/compare/compare.js"}
13+
RESULTS_DIR=${RESULTS_DIR:-"$ROOT/results/$TIMESTAMP-$NAME"}
14+
15+
setup() {
16+
mkdir -p "${RESULTS_DIR}"
17+
}
18+
19+
bench_jobs() {
20+
mode=$1
21+
n=$2
22+
jobs=$3
23+
24+
echo "BENCH: mode=$mode n=$n jobs=$jobs"
25+
26+
TESTS="$ROOT" \
27+
BENCHMARK="jobs=$jobs" \
28+
EARL="${RESULTS_DIR}/$mode-$n-$jobs.earl" \
29+
TEST_ENV="auto,label='$jobs',comment='mode=$mode'" \
30+
npm run test-node
31+
}
32+
33+
bench_mode() {
34+
mode=$1
35+
36+
bench_jobs "$mode" 001 1
37+
bench_jobs "$mode" 002 2
38+
bench_jobs "$mode" 003 5
39+
bench_jobs "$mode" 004 10
40+
bench_jobs "$mode" 005 20
41+
}
42+
43+
bench() {
44+
ASYNC=1 SYNC=0 WEBCRYPTO=0 bench_mode async
45+
ASYNC=0 SYNC=1 WEBCRYPTO=0 bench_mode sync
46+
ASYNC=0 SYNC=0 WEBCRYPTO=1 bench_mode webcrypto
47+
}
48+
49+
report() {
50+
dir=${1:-$RESULTS_DIR}
51+
52+
echo "# async"
53+
echo
54+
node "$COMPAREJS" -r -e combined "$dir"/async-*.earl
55+
echo
56+
echo "# sync"
57+
echo
58+
node "$COMPAREJS" -r -e combined "$dir"/sync-*.earl
59+
echo
60+
echo "# webcrypto"
61+
echo
62+
node "$COMPAREJS" -r -e combined "$dir"/webcrypto-*.earl
63+
}
64+
65+
if [ "$1" = "report" ]; then
66+
if [ "$2" = "" ]; then
67+
echo "Error: report dir required."
68+
exit 1
69+
fi
70+
report "$2"
71+
exit 0
72+
fi
73+
74+
setup
75+
bench
76+
report

0 commit comments

Comments
 (0)