Skip to content

Commit 0ad65f3

Browse files
authored
Make benchmark results more stable by running tests 5 times. (#8863)
1 parent 9f6c983 commit 0ad65f3

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/HotChocolate/AspNetCore/benchmarks/k6/run-and-collect.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ NC='\033[0m' # No Color
1111

1212
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
1313
OUTPUT_FILE="${1:-$SCRIPT_DIR/performance-data.json}"
14-
NUM_RUNS=3
14+
NUM_RUNS=5
1515

1616
echo -e "${BLUE}========================================${NC}"
1717
echo -e "${BLUE}k6 Performance Test Collector${NC}"
@@ -21,24 +21,26 @@ echo "Output file: $OUTPUT_FILE"
2121
echo "Running each test ${NUM_RUNS} times to reduce variance"
2222
echo ""
2323

24-
# Function to calculate median of 3 values
24+
# Function to calculate median from multiple values
2525
calculate_median() {
2626
local values=("$@")
27+
local count=${#values[@]}
2728
# Sort the values
2829
IFS=$'\n' sorted=($(sort -n <<<"${values[*]}"))
2930
unset IFS
30-
# Return the middle value
31-
echo "${sorted[1]}"
31+
# Return the middle value (for odd number of values)
32+
local middle_index=$(( (count - 1) / 2 ))
33+
echo "${sorted[$middle_index]}"
3234
}
3335

34-
# Run single-fetch test 3 times
36+
# Run single-fetch test multiple times
3537
echo -e "${BLUE}Running Single Fetch Test (${NUM_RUNS} runs)...${NC}"
3638
for i in $(seq 1 $NUM_RUNS); do
3739
echo -e "${YELLOW} Run $i/$NUM_RUNS${NC}"
3840
k6 run --summary-export=/tmp/single-fetch-summary-${i}.json "$SCRIPT_DIR/single-fetch.js"
3941
done
4042

41-
# Run dataloader test 3 times
43+
# Run dataloader test multiple times
4244
echo -e "${BLUE}Running DataLoader Test (${NUM_RUNS} runs)...${NC}"
4345
for i in $(seq 1 $NUM_RUNS); do
4446
echo -e "${YELLOW} Run $i/$NUM_RUNS${NC}"

0 commit comments

Comments
 (0)