1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Usage:
|
4 | # ./run.sh <function name>
|
5 |
|
6 | set -o nounset
|
7 | set -o pipefail
|
8 | set -o errexit
|
9 |
|
10 | DIR=benchmarks/javascript
|
11 |
|
12 | # TODO:
|
13 | # - Use benchmarks/time.py for this and make a table
|
14 | # - Upgrade quickjs
|
15 |
|
16 | run-all() {
|
17 | local name=$1
|
18 | shift
|
19 | set -x
|
20 |
|
21 | time $DIR/$name.py "$@"
|
22 |
|
23 | time $DIR/$name.js "$@"
|
24 |
|
25 | time ~/src/duktape-2.5.0/duk $DIR/$name.js "$@"
|
26 | time ~/src/languages/quickjs-2019-07-09/qjs $DIR/$name.js "$@"
|
27 |
|
28 | time bash $DIR/$name.sh "$@"
|
29 | time zsh $DIR/$name.sh "$@"
|
30 |
|
31 | # OSH under CPython: 21.5 seconds. 10x slower.
|
32 | time bin/osh $DIR/$name.sh "$@"
|
33 | }
|
34 |
|
35 | # integers is a lot harder for shell than hexstring
|
36 | # searching through 1000 * 1000 = 1M.
|
37 |
|
38 | # duktape = 89 ms
|
39 | # quickjs = 18 ms # beats node probably because of startup time
|
40 | # node = 32 ms
|
41 | #
|
42 | # zsh: 1.2 seconds. bash 2.5 seconds. So JS has a big advantage here.
|
43 |
|
44 | squares() { run-all squares; }
|
45 |
|
46 | # duktape = 123ms
|
47 | # quickjs = 71ms
|
48 | # node.js = 38ms. Not bad although that may be startup time.
|
49 | # this is searching through a loop of 16 * 16 * 16 = 4096.
|
50 | #
|
51 | # zsh: 150 ms, bash: 165ms. Not as big an advantage. But still JS is better
|
52 | # for code readability.
|
53 | hexstring() { run-all hexstring; }
|
54 |
|
55 |
|
56 | "$@"
|