-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathbenchmark.sh
More file actions
executable file
·37 lines (28 loc) · 1.06 KB
/
benchmark.sh
File metadata and controls
executable file
·37 lines (28 loc) · 1.06 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
#!/bin/bash
# Check if the required arguments are provided
if [[ $# -lt 1 ]]; then
echo "Usage: $0 <DB_NAME> [RESULT_FILE]"
exit 1
fi
# Arguments
DB_NAME="$1"
RESULT_FILE="${2:-}"
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $(basename "$0") START"
# Construct the query log file name using $DB_NAME
# QUERY_LOG_FILE="${OUTPUT_PREFIX}_query_log_${DB_NAME}.txt"
QUERY_LOG_FILE="${OUTPUT_PREFIX}_${DB_NAME}.query_log"
# Print the database name
echo "Running queries on database: $DB_NAME"
# Run queries and log the output
./run_queries.sh "$DB_NAME" 2>&1 | tee "$QUERY_LOG_FILE"
# Process the query log and prepare the result
RESULT=$(cat "$QUERY_LOG_FILE" | grep -oP 'Time: \d+\.\d+ ms' | sed -r -e 's/Time: ([0-9]+\.[0-9]+) ms/\1/' | \
awk '{ if (i % 3 == 0) { printf "[" }; printf $1 / 1000; if (i % 3 != 2) { printf "," } else { print "]," }; ++i; }')
# Output the result
if [[ -n "$RESULT_FILE" ]]; then
echo "$RESULT" > "$RESULT_FILE"
echo "Result written to $RESULT_FILE"
else
echo "$RESULT"
fi
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $(basename "$0") DONE"