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

107 lines, 57 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# Used in benchmarks/gc and benchmarks/compute
56banner() {
57 echo -----
58 echo "$@"
59}
60
61cmark() {
62 # A filter to making reports
63 PYTHONPATH=.:vendor doctools/cmark.py "$@"
64}
65
66# For compatibility, if cell starts with 'osh', apply the 'special' CSS class.
67csv2html() {
68 web/table/csv2html.py --css-class-pattern 'special ^osh' "$@"
69}
70
71# also in metrics/source-code.sh
72hist() { sort | uniq -c | sort -n; }
73
74html-head() {
75 PYTHONPATH=. doctools/html_head.py "$@"
76}
77
78benchmark-html-head() {
79 local title="$1"
80
81 local base_url='../../web'
82
83 html-head --title "$title" \
84 "$base_url/table/table-sort.js" \
85 "$base_url/table/table-sort.css" \
86 "$base_url/base.css"\
87 "$base_url/benchmarks.css"
88}
89
90filter-provenance() {
91 # create a regex bash|dash
92 local pat=$(echo "$@" | sed 's/ /|/g')
93
94 # Anchor it at the end only. For _bin/cxx-opt/oils-for-unix.stripped and the
95 # ../benchmark-data one.
96 pat="($pat)\$"
97
98 # 4th column is the shell
99 awk -v pat="$pat" '$4 ~ pat { print }'
100}
101
102maybe-tree() {
103 ### Run tree command if it's installed
104 if command -v tree; then
105 tree "$@"
106 fi
107}