|
#!/bin/bash |
|
# |
|
# Example: |
|
# ../bench.sh ../{sphere_1000,2_spheres_1000}.scad "../poly_attached_inlined.scad -Dsingle=true" "../poly_attached_inlined.scad -Dsingle=false" |
|
# |
|
# |
|
set -euo pipefail |
|
|
|
# Times each file is run in each mode / branch |
|
RUNS=${RUNS:-10} |
|
|
|
# Parallelism (don't put more here than you have virtual cores) |
|
N=${N:-10} |
|
|
|
# Relative path of the binary inside the build folder. This default is for MacOS. |
|
BINARY=${BINARY:-OpenSCAD.app/Contents/MacOS/OpenSCAD} |
|
|
|
# Pass list of files as arguments |
|
FILES=( "$@" ) |
|
|
|
BRANCHES=( |
|
fast-integ |
|
master |
|
fast-stl3 |
|
identifiers |
|
vector-reserve |
|
polyset-reserve |
|
virtual-simplify |
|
remove-dupe-vars |
|
frame-reserve |
|
) |
|
|
|
FORMATS=( |
|
binstl |
|
asciistl |
|
echo |
|
) |
|
|
|
function join_by { |
|
local IFS="$1" |
|
shift |
|
echo "$*" |
|
} |
|
|
|
function build_branch() { |
|
local branch="$1" |
|
echo "# Building branch $branch" |
|
git checkout $branch |
|
git pull |
|
|
|
mkdir -p build-$branch |
|
cd build-$branch |
|
|
|
if [[ ! -f Makefile || ../CMakeLists.txt -nt Makefile ]]; then |
|
cmake -DCMAKE_BUILD_TYPE=Release -DEXPERIMENTAL=1 -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=1 .. |
|
fi |
|
|
|
make -j${N} |
|
} |
|
|
|
if [[ "${BUILD:-1}" == 1 ]]; then |
|
for branch in "${BRANCHES[@]}" ; do |
|
( build_branch "$branch" ) |
|
done |
|
fi |
|
|
|
TIMESTAMP=$( gdate '+%Y%m%d-%H%M' ) |
|
|
|
echo "# Results" > bench-results-${TIMESTAMP}.md |
|
|
|
for format in "${FORMATS[@]}" ; do |
|
|
|
echo " |
|
## ${format} |
|
" >> bench-results-${TIMESTAMP}.md |
|
|
|
for file in "${FILES[@]}" ; do |
|
filename=$(basename -- "$file") |
|
filenamestem=$(echo "$filename" | sed -E 's/[^a-zA-Z0-9]+/_/g' ) |
|
|
|
branches=() |
|
|
|
for branch in "${BRANCHES[@]}" ; do |
|
if [[ "$format" == "asciistl" ]]; then |
|
if [[ "$branch" == *stl* || "$branch" == master ]]; then |
|
branches+=( "$branch" ) |
|
fi |
|
else |
|
branches+=( "$branch" ) |
|
fi |
|
done |
|
|
|
echo " |
|
### ${filename} → ${format} |
|
" >> bench-results-${TIMESTAMP}.md |
|
|
|
hyperfine_args=( |
|
-i |
|
-L branch "$( join_by , "${branches[@]}" )" |
|
# -L format "binstl,asciistl,echo" |
|
# -L file "$( join_by , "${FILES[@]}" )" |
|
--warmup 1 |
|
--runs "$RUNS" |
|
--export-json "bench-results-${TIMESTAMP}-${filenamestem}-${format}.json" |
|
--export-markdown "bench-results-${TIMESTAMP}-${filenamestem}-${format}.md" |
|
"./build-{branch}/${BINARY} ${file} -o out --export-format=${format} --enable=manifold" |
|
) |
|
|
|
echo "# Rendering ${file} to format ${format} with ${#branches[@]} branches: $( join_by , "${branches[@]}" )" |
|
hyperfine "${hyperfine_args[@]}" |
|
|
|
cat "bench-results-${TIMESTAMP}-${filenamestem}-${format}.md" >> bench-results-${TIMESTAMP}.md |
|
done |
|
done |
|
|
|
sed -E -i.bak 's/`.\/build-([^/]+)[^`]+`/\1/g' bench-results-${TIMESTAMP}.md |
|
sed -E -i.bak 's/\| Command \|/| Branch |/g' bench-results-${TIMESTAMP}.md |
|
|
|
echo " |
|
|
|
bench-results-${TIMESTAMP}.md |
|
" |
|
|
|
# hyperfine_args=( |
|
# -i |
|
# -L branch "$( join_by , "${BRANCHES[@]}" )" |
|
# -L format "binstl,asciistl,echo" |
|
# -L file "$( join_by , "${FILES[@]}" )" |
|
# --warmup 1 |
|
# --runs "$RUNS" |
|
# --export-json "bench-results-${TIMESTAMP}.json" |
|
# --export-markdown "bench-results-${TIMESTAMP}.md" |
|
# "./build-{branch}/${BINARY} {file} -o out --export-format={format} --enable=manifold" |
|
# ) |
|
|
|
# hyperfine "${hyperfine_args[@]}" |