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

115 lines, 61 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
16OILS_VERSION=$(head -n 1 oils-version.txt)
17
18readonly _NINJA_BUILD=_bin/cxx-opt
19readonly OSH_CPP_NINJA=$_NINJA_BUILD/osh
20readonly OSH_SOUFFLE_CPP_NINJA=$_NINJA_BUILD/mycpp-souffle/osh
21
22# Used by devtools/release.sh
23readonly BENCHMARK_DATA_OILS=$PWD/../benchmark-data/src/oils-for-unix-$OILS_VERSION
24readonly _SH_BUILD=_bin/cxx-opt-sh
25
26readonly OSH_CPP_SOIL=$_SH_BUILD/osh
27readonly OSH_SOUFFLE_CPP_SOIL=$_SH_BUILD/mycpp-souffle/osh
28
29readonly OSH_CPP_TWO=$BENCHMARK_DATA_OILS/$OSH_CPP_SOIL
30readonly OSH_SOUFFLE_CPP_TWO=$BENCHMARK_DATA_OILS/$OSH_SOUFFLE_CPP_SOIL
31
32readonly YSH_CPP_SOIL=$_SH_BUILD/ysh
33readonly YSH_CPP_TWO=$BENCHMARK_DATA_OILS/$YSH_CPP_SOIL
34
35# We always build from the tarball
36readonly OSH_STATIC_SOIL=$_SH_BUILD/osh-static
37readonly OSH_STATIC_TWO=$BENCHMARK_DATA_OILS/$OSH_STATIC_SOIL
38
39
40#
41# Binaries we want to test, which can be overridden
42#
43
44OSH_OVM=${OSH_OVM:-_bin/osh} # This is overridden by devtools/release.sh.
45
46readonly OTHER_SHELLS=( bash dash mksh zsh )
47readonly 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.
51readonly OSH_CPP_REGEX='_bin/.*/osh'
52
53log() {
54 echo "$@" >&2
55}
56
57# NOTE: This is in {build,test}/common.sh too.
58die() {
59 log "$0: fatal: $@"
60 exit 1
61}
62
63# Used in benchmarks/gc and benchmarks/compute
64banner() {
65 echo -----
66 echo "$@"
67}
68
69cmark() {
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.
75csv2html() {
76 web/table/csv2html.py --css-class-pattern 'special ^osh' "$@"
77}
78
79# also in metrics/source-code.sh
80hist() { sort | uniq -c | sort -n; }
81
82html-head() {
83 PYTHONPATH=. doctools/html_head.py "$@"
84}
85
86benchmark-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
98filter-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
110maybe-tree() {
111 ### Run tree command if it's installed
112 if command -v tree; then
113 tree "$@"
114 fi
115}