Skip to content

Commit

Permalink
Post-review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
berestovskyy committed Dec 10, 2024
1 parent 5ca95d3 commit 99c7022
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
26 changes: 16 additions & 10 deletions rs/execution_environment/benches/run-all-benchmarks.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh -eu
#!/usr/bin/env bash
set -ue
##
## Top-level script to run all execution and embedder benchmarks.
## Usage:
Expand All @@ -17,26 +18,31 @@ run() {
local i="${1}"
local name="${2}"
local bench="${3}"
# File with best (min) results.
local min_file="${4}"
local filter="${5:-}"

repeated_file="${min_file%.*}.repeated"
repeated=$(cat "${repeated_file}" 2>/dev/null || echo "-1")
[ "${repeated}" -eq "-1" ] && quick="yes" || quick="no"
[ -f "${min_file}" ] || repeated="-1"
if [ "${repeated}" -lt "${i}" ]; then
echo "==> Running ${name} benchmarks ($((repeated + 1)) of ${REPEAT})"
# Counter file tracks the number of benchmark executions so far.
counter_file="${min_file%.*}.counter"
counter=$(cat "${counter_file}" 2>/dev/null || echo "-1")
# Quickly execute the benchmarks initially to identify any broken ones.
[ "${counter}" -eq "-1" ] && quick="yes" || quick="no"
[ -f "${min_file}" ] || counter="-1"
# Execute benchmark if needed.
if [ "${counter}" -lt "${i}" ]; then
echo "==> Running ${name} benchmarks ($((counter + 1)) of ${REPEAT})"
QUICK="${quick}" BENCH="${bench}" MIN_FILE="${min_file}" FILTER="${filter}" \
"${RUN_BENCHMARK}"
echo "$((repeated + 1))" >"${repeated_file}"
echo "$((counter + 1))" >"${counter_file}"
fi
if [ "${repeated}" -lt "${i}" -o "${i}" = "${REPEAT}" ]; then
# Summarize results if the benchmark was executed or if it's the final iteration.
if [ "${counter}" -lt "${i}" -o "${i}" = "${REPEAT}" ]; then
echo "==> Summarizing ${name} results:"
NAME="${name}" MIN_FILE="${min_file}" "${SUMMARIZE_RESULTS}"
fi
}

for i in $(seq 0 ${REPEAT}); do
for i in $(seq 0 "${REPEAT}"); do
run "${i}" "Embedders Compilation" \
"//rs/embedders:compilation_bench" "EMBEDDERS_COMPILATION.min"
run "${i}" "Embedders Heap" \
Expand Down
7 changes: 4 additions & 3 deletions rs/execution_environment/benches/run-benchmark.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh -eu
#!/usr/bin/env bash
set -ue
##
## Helper script to run the specified `BENCH`
## and store the best (min) results in the `MIN_FILE`.
Expand Down Expand Up @@ -31,7 +32,7 @@ bash -c "set -o pipefail; \
)

if ! [ -s "${MIN_FILE}" ]; then
echo " Setting a new baseline in ${MIN_FILE}"
echo " Storing results in ${MIN_FILE}"
cat "${LOG_FILE}" | rg "^test .* bench:" >"${MIN_FILE}" || echo " No results (quick run?)"
else
echo " Merging ${LOG_FILE} into ${MIN_FILE}"
Expand All @@ -46,7 +47,7 @@ else
min_result=$(echo "${min_bench}" | sed -E 's/.*bench: +([0-9]+) ns.*/\1/')

if [ -z "${min_result}" ] || [ "${new_result}" -lt "${min_result}" ]; then
echo " - improved ${name} time: $((new_result / 1000)) ms"
echo " - improved ${name} time: $((new_result / 1000)) µs"
min_bench="${new_bench}"
fi
echo "${min_bench}" >>"${TMP_FILE}"
Expand Down
3 changes: 2 additions & 1 deletion rs/execution_environment/benches/summarize-results.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh -eu
#!/usr/bin/env bash
set -ue
##
## Helper script to summarize the results in the `MIN_FILE`
## comparing them to the `BASELINE_DIR` results.
Expand Down

0 comments on commit 99c7022

Please sign in to comment.