-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbench.sh
More file actions
executable file
·49 lines (39 loc) · 1.71 KB
/
bench.sh
File metadata and controls
executable file
·49 lines (39 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
# Benchmark script for RayON renderer
# Usage: ./bench.sh [runs] [label] [mode]
# runs: number of iterations (default: 5)
# label: descriptive label for this benchmark run
# mode: rendering mode (default: 2 = CUDA, 4 = OptiX)
RUNS=${1:-5}
LABEL=${2:-"unlabeled"}
MODE=${3:-2}
RESULTS_FILE="bench_results.csv"
# Create results file with header if it doesn't exist
if [ ! -f "$RESULTS_FILE" ]; then
echo "timestamp,label,run,time_s,rays_traced,rays_per_sec" > "$RESULTS_FILE"
fi
echo "=== Benchmark: $LABEL ($RUNS runs, mode $MODE) ==="
times=()
rays_arr=()
rps_arr=()
for i in $(seq 1 $RUNS); do
output=$(./rayon -m $MODE -s 1024 -r 1080 2>&1)
time_s=$(echo "$output" | grep -oP 'completed in \K[0-9.]+')
rays=$(echo "$output" | grep -oP 'Rays traced: \K[0-9,]+' | tr -d ',')
rps=$(echo "$output" | grep -oP 'Rays/sec: \K[0-9,]+' | tr -d ',')
times+=($time_s)
rays_arr+=($rays)
rps_arr+=($rps)
ts=$(date +%Y-%m-%dT%H:%M:%S)
echo "$ts,$LABEL,$i,$time_s,$rays,$rps" >> "$RESULTS_FILE"
printf " Run %d: %6.2fs | Rays: %s | Rays/s: %s\n" "$i" "$time_s" "$rays" "$rps"
done
# Compute averages using awk
avg_time=$(printf '%s\n' "${times[@]}" | awk '{s+=$1} END {printf "%.2f", s/NR}')
avg_rays=$(printf '%s\n' "${rays_arr[@]}" | awk '{s+=$1} END {printf "%.0f", s/NR}')
avg_rps=$(printf '%s\n' "${rps_arr[@]}" | awk '{s+=$1} END {printf "%.0f", s/NR}')
# Compute std dev for time
std_time=$(printf '%s\n' "${times[@]}" | awk -v avg="$avg_time" '{d=$1-avg; s+=d*d} END {printf "%.2f", sqrt(s/NR)}')
echo "---"
printf " Avg: %6.2fs ± %4.2fs | Avg Rays: %s | Avg Rays/s: %s\n" "$avg_time" "$std_time" "$avg_rays" "$avg_rps"
echo "=== Results appended to $RESULTS_FILE ==="