1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Common functions for benchmarks.
|
4 | #
|
5 |
|
6 | # Include guard.
|
7 | test -n "${__BENCHMARKS_COMMON_SH:-}" && return
|
8 | readonly __BENCHMARKS_COMMON_SH=1
|
9 |
|
10 | # 2024-12: Moved back to local machines
|
11 |
|
12 | readonly MACHINE1=hoover
|
13 | readonly MACHINE2=lenny
|
14 | #readonly MACHINE2=mercer
|
15 |
|
16 | OILS_VERSION=$(head -n 1 oils-version.txt)
|
17 |
|
18 | readonly _NINJA_BUILD=_bin/cxx-opt
|
19 | readonly OSH_CPP_NINJA=$_NINJA_BUILD/osh
|
20 | readonly OSH_SOUFFLE_CPP_NINJA=$_NINJA_BUILD/mycpp-souffle/osh
|
21 |
|
22 | # Used by devtools/release.sh
|
23 | readonly BENCHMARK_DATA_OILS=$PWD/../benchmark-data/src/oils-for-unix-$OILS_VERSION
|
24 | readonly _SH_BUILD=_bin/cxx-opt-sh
|
25 |
|
26 | readonly OSH_CPP_SOIL=$_SH_BUILD/osh
|
27 | readonly OSH_SOUFFLE_CPP_SOIL=$_SH_BUILD/mycpp-souffle/osh
|
28 |
|
29 | readonly OSH_CPP_TWO=$BENCHMARK_DATA_OILS/$OSH_CPP_SOIL
|
30 | readonly OSH_SOUFFLE_CPP_TWO=$BENCHMARK_DATA_OILS/$OSH_SOUFFLE_CPP_SOIL
|
31 |
|
32 | readonly YSH_CPP_SOIL=$_SH_BUILD/ysh
|
33 | readonly YSH_CPP_TWO=$BENCHMARK_DATA_OILS/$YSH_CPP_SOIL
|
34 |
|
35 | # We always build from the tarball
|
36 | readonly OSH_STATIC_SOIL=$_SH_BUILD/osh-static
|
37 | readonly OSH_STATIC_TWO=$BENCHMARK_DATA_OILS/$OSH_STATIC_SOIL
|
38 |
|
39 |
|
40 | #
|
41 | # Binaries we want to test, which can be overridden
|
42 | #
|
43 |
|
44 | OSH_OVM=${OSH_OVM:-_bin/osh} # This is overridden by devtools/release.sh.
|
45 |
|
46 | readonly OTHER_SHELLS=( bash dash mksh zsh )
|
47 | readonly SHELLS=( ${OTHER_SHELLS[@]} bin/osh $OSH_OVM )
|
48 |
|
49 | # Passed to awk in filter-provenance. TODO: This could be a parameter
|
50 | # Awk wants this to be \\. ? Probably should stop using Awk.
|
51 | readonly OSH_CPP_REGEX='_bin/.*/osh'
|
52 |
|
53 | log() {
|
54 | echo "$@" >&2
|
55 | }
|
56 |
|
57 | # NOTE: This is in {build,test}/common.sh too.
|
58 | die() {
|
59 | log "$0: fatal: $@"
|
60 | exit 1
|
61 | }
|
62 |
|
63 | # Used in benchmarks/gc and benchmarks/compute
|
64 | banner() {
|
65 | echo -----
|
66 | echo "$@"
|
67 | }
|
68 |
|
69 | cmark() {
|
70 | # A filter to making reports
|
71 | PYTHONPATH=.:vendor doctools/cmark.py "$@"
|
72 | }
|
73 |
|
74 | # For compatibility, if cell starts with 'osh', apply the 'special' CSS class.
|
75 | csv2html() {
|
76 | web/table/csv2html.py --css-class-pattern 'special ^osh' "$@"
|
77 | }
|
78 |
|
79 | # also in metrics/source-code.sh
|
80 | hist() { sort | uniq -c | sort -n; }
|
81 |
|
82 | html-head() {
|
83 | PYTHONPATH=. doctools/html_head.py "$@"
|
84 | }
|
85 |
|
86 | benchmark-html-head() {
|
87 | local title="$1"
|
88 |
|
89 | local base_url='../../web'
|
90 |
|
91 | html-head --title "$title" \
|
92 | "$base_url/table/table-sort.js" \
|
93 | "$base_url/table/table-sort.css" \
|
94 | "$base_url/base.css" \
|
95 | "$base_url/benchmarks.css"
|
96 | }
|
97 |
|
98 | filter-provenance() {
|
99 | # create a regex bash|dash
|
100 | local pat=$(echo "$@" | sed 's/ /|/g')
|
101 |
|
102 | # Anchor it at the end only. For _bin/cxx-opt/oils-for-unix.stripped and the
|
103 | # ../benchmark-data one.
|
104 | pat="($pat)\$"
|
105 |
|
106 | # 4th column is the shell
|
107 | awk -v pat="$pat" '$4 ~ pat { print }'
|
108 | }
|
109 |
|
110 | maybe-tree() {
|
111 | ### Run tree command if it's installed
|
112 | if command -v tree; then
|
113 | tree "$@"
|
114 | fi
|
115 | }
|