OILS / benchmarks / common.sh View on Github | oilshell.org

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