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 | OIL_VERSION=$(head -n 1 oils-version.txt)
|
17 |
|
18 | # Used by devtools/release.sh
|
19 | readonly BENCHMARK_DATA_OILS=$PWD/../benchmark-data/src/oils-for-unix-$OIL_VERSION
|
20 |
|
21 | readonly OSH_CPP_NINJA_BUILD=_bin/cxx-opt/osh
|
22 | readonly OSH_SOUFFLE_CPP_NINJA_BUILD=_bin/cxx-opt/mycpp-souffle/osh
|
23 |
|
24 | readonly OSH_CPP_SH_BUILD=_bin/cxx-opt-sh/osh
|
25 | readonly OSH_SOUFFLE_CPP_SH_BUILD=_bin/cxx-opt-sh/mycpp-souffle/osh
|
26 | readonly YSH_CPP_SH_BUILD=_bin/cxx-opt-sh/ysh
|
27 |
|
28 | readonly OSH_CPP_BENCHMARK_DATA=$BENCHMARK_DATA_OILS/$OSH_CPP_SH_BUILD
|
29 | readonly OSH_SOUFFLE_CPP_BENCHMARK_DATA=$BENCHMARK_DATA_OILS/$OSH_SOUFFLE_CPP_SH_BUILD
|
30 | readonly YSH_CPP_BENCHMARK_DATA=$BENCHMARK_DATA_OILS/$YSH_CPP_SH_BUILD
|
31 |
|
32 | #
|
33 | # Binaries we want to test, which can be overridden
|
34 | #
|
35 |
|
36 | OSH_OVM=${OSH_OVM:-_bin/osh} # This is overridden by devtools/release.sh.
|
37 |
|
38 | readonly OTHER_SHELLS=( bash dash mksh zsh )
|
39 | readonly SHELLS=( ${OTHER_SHELLS[@]} bin/osh $OSH_OVM )
|
40 |
|
41 | # Passed to awk in filter-provenance. TODO: This could be a parameter
|
42 | # Awk wants this to be \\. ? Probably should stop using Awk.
|
43 | readonly OSH_CPP_REGEX='_bin/.*/osh'
|
44 |
|
45 | log() {
|
46 | echo "$@" >&2
|
47 | }
|
48 |
|
49 | # NOTE: This is in {build,test}/common.sh too.
|
50 | die() {
|
51 | log "$0: fatal: $@"
|
52 | exit 1
|
53 | }
|
54 |
|
55 |
|
56 | cmark() {
|
57 | # A filter to making reports
|
58 | PYTHONPATH=.:vendor doctools/cmark.py "$@"
|
59 | }
|
60 |
|
61 | # For compatibility, if cell starts with 'osh', apply the 'special' CSS class.
|
62 | csv2html() {
|
63 | web/table/csv2html.py --css-class-pattern 'special ^osh' "$@"
|
64 | }
|
65 |
|
66 | # also in metrics/source-code.sh
|
67 | hist() { sort | uniq -c | sort -n; }
|
68 |
|
69 | html-head() {
|
70 | PYTHONPATH=. doctools/html_head.py "$@"
|
71 | }
|
72 |
|
73 | benchmark-html-head() {
|
74 | local title="$1"
|
75 |
|
76 | local base_url='../../web'
|
77 |
|
78 | html-head --title "$title" \
|
79 | "$base_url/table/table-sort.js" \
|
80 | "$base_url/table/table-sort.css" \
|
81 | "$base_url/base.css"\
|
82 | "$base_url/benchmarks.css"
|
83 | }
|
84 |
|
85 | filter-provenance() {
|
86 | # create a regex bash|dash
|
87 | local pat=$(echo "$@" | sed 's/ /|/g')
|
88 |
|
89 | # Anchor it at the end only. For _bin/cxx-opt/oils-for-unix.stripped and the
|
90 | # ../benchmark-data one.
|
91 | pat="($pat)\$"
|
92 |
|
93 | # 4th column is the shell
|
94 | awk -v pat="$pat" '$4 ~ pat { print }'
|
95 | }
|
96 |
|
97 | maybe-tree() {
|
98 | ### Run tree command if it's installed
|
99 | if command -v tree; then
|
100 | tree "$@"
|
101 | fi
|
102 | }
|