summaryrefslogtreecommitdiffstats
path: root/test_prompts.sh
diff options
context:
space:
mode:
Diffstat (limited to 'test_prompts.sh')
-rwxr-xr-xtest_prompts.sh30
1 files changed, 21 insertions, 9 deletions
diff --git a/test_prompts.sh b/test_prompts.sh
index 3178efb..04020c3 100755
--- a/test_prompts.sh
+++ b/test_prompts.sh
@@ -17,8 +17,8 @@ if [ ! -f "$PROMPT_FILE" ]; then
exit 1
fi
-# Count total valid prompts (ignoring empty lines and comments)
-total_prompts=$(grep -cvE '^[[:space:]]*($|#)' "$PROMPT_FILE")
+# Count valid prompts using POSIX awk to avoid ksh $(...) parenthetical syntax errors
+total_prompts=$(awk '/^[[:space:]]*($|#)/ {next} {count++} END {print count+0}' "$PROMPT_FILE")
if [ "$total_prompts" -eq 0 ]; then
echo "No valid prompts found in '$PROMPT_FILE'."
@@ -43,6 +43,10 @@ echo "---------------------------------------------------"
current=0
first=1
+# Temporary file to capture time / rusage output
+TIME_LOG=$(mktemp /tmp/lex_time.XXXXXX)
+trap 'rm -f "$TIME_LOG"' EXIT
+
# Process each prompt line by line
while IFS= read -r prompt || [ -n "$prompt" ]; do
# Skip empty lines or comment lines starting with #
@@ -52,9 +56,6 @@ while IFS= read -r prompt || [ -n "$prompt" ]; do
current=$((current + 1))
- # Print real-time progress to terminal
- printf "[%d/%d] Running: %s\n" "$current" "$total_prompts" "$prompt"
-
# Add delimiter before every prompt except the first in the results file
if [ "$first" -eq 1 ]; then
first=0
@@ -65,11 +66,22 @@ while IFS= read -r prompt || [ -n "$prompt" ]; do
# Log prompt header to the result file
printf "PROMPT: %s\n\n" "$prompt" >> "$RESULT_FILE"
- # Invoke the executable and append output to result file
- "$EXECUTABLE" "$prompt" >> "$RESULT_FILE" 2>&1
+ # On OpenBSD, /usr/bin/time -lp outputs POSIX timings and rusage stats to stderr
+ /usr/bin/time -lp "$EXECUTABLE" "$prompt" >> "$RESULT_FILE" 2> "$TIME_LOG"
+
+ # Extract execution time and peak memory (maximum resident set size) from OpenBSD time output
+ real_time=$(awk '/^real/ {print $2}' "$TIME_LOG")
+ max_rss_mb=$(awk '/maximum resident set size/ {printf "%.2f", $1/1024}' "$TIME_LOG")
+
+ # Format metrics summary line
+ metrics_summary="ELAPSED: ${real_time}s | MAX RSS: ${max_rss_mb} MB"
+
+ # Append metrics to result file
+ printf "METRICS: %s\n\n" "$metrics_summary" >> "$RESULT_FILE"
+
+ # Print real-time progress to terminal
+ printf "[%d/%d] Done: %s (%s)\n" "$current" "$total_prompts" "$prompt" "$metrics_summary"
- # Ensure a trailing newline after output
- printf "\n" >> "$RESULT_FILE"
done < "$PROMPT_FILE"
echo "---------------------------------------------------"