OILS / benchmarks / common.sh View on Github | oils.pub

102 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# 2024-12: Moved back to local machines
11
12readonly MACHINE1=hoover
13readonly MACHINE2=lenny
14#readonly MACHINE2=mercer
15
16OIL_VERSION=$(head -n 1 oils-version.txt)
17
18# Used by devtools/release.sh
19readonly BENCHMARK_DATA_OILS=$PWD/../benchmark-data/src/oils-for-unix-$OIL_VERSION
20
21readonly OSH_CPP_NINJA_BUILD=_bin/cxx-opt/osh
22readonly OSH_SOUFFLE_CPP_NINJA_BUILD=_bin/cxx-opt/mycpp-souffle/osh
23
24readonly OSH_CPP_SH_BUILD=_bin/cxx-opt-sh/osh
25readonly OSH_SOUFFLE_CPP_SH_BUILD=_bin/cxx-opt-sh/mycpp-souffle/osh
26readonly YSH_CPP_SH_BUILD=_bin/cxx-opt-sh/ysh
27
28readonly OSH_CPP_BENCHMARK_DATA=$BENCHMARK_DATA_OILS/$OSH_CPP_SH_BUILD
29readonly OSH_SOUFFLE_CPP_BENCHMARK_DATA=$BENCHMARK_DATA_OILS/$OSH_SOUFFLE_CPP_SH_BUILD
30readonly 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
36OSH_OVM=${OSH_OVM:-_bin/osh} # This is overridden by devtools/release.sh.
37
38readonly OTHER_SHELLS=( bash dash mksh zsh )
39readonly 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.
43readonly OSH_CPP_REGEX='_bin/.*/osh'
44
45log() {
46 echo "$@" >&2
47}
48
49# NOTE: This is in {build,test}/common.sh too.
50die() {
51 log "$0: fatal: $@"
52 exit 1
53}
54
55
56cmark() {
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.
62csv2html() {
63 web/table/csv2html.py --css-class-pattern 'special ^osh' "$@"
64}
65
66# also in metrics/source-code.sh
67hist() { sort | uniq -c | sort -n; }
68
69html-head() {
70 PYTHONPATH=. doctools/html_head.py "$@"
71}
72
73benchmark-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
85filter-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
97maybe-tree() {
98 ### Run tree command if it's installed
99 if command -v tree; then
100 tree "$@"
101 fi
102}