@@ -17,9 +17,6 @@ bm_project=$(realpath -e "$bm_project") # ensure it's an absolute path and exis
1717declare -x ARTIFACTS_DIR=${ARTIFACTS_DIR:= " $solution_dir /BmResults" }
1818ARTIFACTS_DIR=$( realpath -m " $ARTIFACTS_DIR " ) # ensure it's an absolute path
1919
20- declare -x SUMMARIES_DIR=${SUMMARIES_DIR:= " $ARTIFACTS_DIR /summaries" }
21- SUMMARIES_DIR=$( realpath -m " $SUMMARIES_DIR " ) # ensure it's an absolute path
22-
2320declare configuration=${CONFIGURATION:= " Release" }
2421
2522source " $script_dir /_common.sh"
@@ -29,10 +26,22 @@ get_arguments "$@"
2926declare -r bm_project
3027declare -r configuration
3128
29+ declare -x results_dir=${results_dir:= " $ARTIFACTS_DIR /results" }
30+ results_dir=$( realpath -m " $results_dir " ) # ensure it's an absolute path
31+ declare -r results_dir
32+
33+ declare -x summaries_dir=${summaries_dir:= " $ARTIFACTS_DIR /summaries" }
34+ summaries_dir=$( realpath -m " $summaries_dir " )
35+ declare -r summaries_dir
36+
37+ declare -x baseline_dir=${baseline_dir:= " $ARTIFACTS_DIR /baseline" }
38+ baseline_dir=$( realpath -m " $baseline_dir " )
39+ declare -r baseline_dir
40+
3241dump_all_variables
3342
3443trace " Creating directory(s)..."
35- execute mkdir -p " $SUMMARIES_DIR "
44+ execute mkdir -p " $summaries_dir "
3645
3746trace " Running benchmark tests in project '$bm_project ' with configuration '$configuration '..."
3847execute mkdir -p " ${ARTIFACTS_DIR} "
@@ -57,7 +66,7 @@ if [[ $dry_run != "true" ]]; then
5766 # it expands to an empty string instead of the default to leaving the pattern unchanged,
5867 # i.e. ${ARTIFACTS_DIR}/results/*-report.json - we don't want that
5968 shopt -s nullglob
60- files=(" ${ ARTIFACTS_DIR} /results/*-report.json" )
69+ files=(" $ARTIFACTS_DIR /results/*-report.json" )
6170 shopt -u nullglob
6271
6372 if [ ${# files[@]} -eq 0 ]; then
@@ -67,6 +76,60 @@ if [[ $dry_run != "true" ]]; then
6776
6877 for f in " ${files[@]} " ; do
6978 sf=$( sed -nE ' s/(.*)-report.json/\1-summary.json/p' <<< " $(basename " ${f} " )" )
70- jq -f " $solution_dir /.github/workflows/summary.jq" " ${f} " > " ${SUMMARIES_DIR } /${sf} "
79+ jq -f " $solution_dir /.github/workflows/summary.jq" " ${f} " > " ${summaries_dir } /${sf} "
7180 done
7281fi
82+
83+ # -------------------------------------------------------------------------------
84+
85+ fs=$( ls " ${summaries_dir} " /* -summary.json 2> /dev/null || true)
86+ if [ -z " ${fs} " ]; then
87+ echo " No current benchmark result JSON files found." >&2
88+ exit 2
89+ fi
90+ sum_cur=0
91+ for f in ${fs} ; do
92+ VAL=$( jq ' ( .Totals.Mean // 0)' " ${f} " )
93+ sum_cur=$(( sum_cur + VAL ))
94+ done
95+ if (( sum_cur == 0 )) ; then
96+ echo " Current sum is invalid (${sum_cur} )." >&2
97+ exit 2
98+ fi
99+
100+ fs=$( ls " ${baseline_dir} " /* -summary.json 2> /dev/null || true)
101+ if [[ -z " ${fs} " ]]; then
102+ echo " Baseline reports were not found at ${baseline_dir} ." >&2
103+ echo " FORCE_NEW_BASELINE=true" >> " $GITHUB_ENV "
104+ exit 0
105+ fi
106+ sum_base=0
107+ for f in ${fs} ; do
108+ VAL=$( jq ' ( .Totals.Mean // 0)' " ${f} " )
109+ sum_base=$(( sum_base + VAL ))
110+ done
111+ if (( sum_base == 0 )) ; then
112+ echo " Baseline sum is invalid (${sum_base} )." >&2
113+ exit 2
114+ fi
115+
116+ pct=$(( (sum_cur - sum_base) * 100 / sum_base ))
117+ echo " Percent change vs baseline: ${pct} % (allowed: ${max_regression_pct} %)"
118+ flush_stdout
119+
120+ if (( pct > max_regression_pct )) ; then
121+ echo " Performance regression exceeds threshold" >&2
122+ exit 2
123+ elif (( pct > 0 )) ; then
124+ echo " Performance regression within acceptable threshold."
125+ flush_stdout
126+ elif (( pct < 0 )) ; then
127+ pct_abs=$(( - pct ))
128+ if (( pct_abs >= max_regression_pct )) ; then
129+ echo " Significant improvement of ${pct_abs} % over baseline. Updating the baseline."
130+ echo " FORCE_NEW_BASELINE=true" >> " $GITHUB_ENV "
131+ else
132+ echo " Improvement of ${pct_abs} % over baseline."
133+ fi
134+ flush_stdout
135+ fi
0 commit comments