Skip to content

Commit 095a466

Browse files
committed
configured performance testing
1 parent c9da067 commit 095a466

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

composer.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@
6868
"test-server": "echo \"Running Test Server\" && php -S localhost:8000 -t tests/server/",
6969
"test-server-v2": "echo \"Running Test Server\" && php -S localhost:8000 -t tests/server-v2/",
7070
"test-coverage:win": "del clover.xml && phpunit --coverage-html=coverage --coverage-clover=clover.xml && coverage-check clover.xml 100",
71+
"test-performance": [
72+
"echo \"Running Performance Tests...\"",
73+
"php -S localhost:8077 -t tests/performance/ > /dev/null 2>&1 & echo $! > server.pid",
74+
"sleep 2",
75+
"bash tests/performance/performance_tests.sh",
76+
"kill `cat server.pid`",
77+
"rm server.pid",
78+
"echo \"Performance Tests Completed.\""
79+
],
7180
"lint": "phpstan --no-progress --memory-limit=256M -cphpstan.neon",
7281
"beautify": "phpcbf --standard=phpcs.xml",
7382
"phpcs": "phpcs --standard=phpcs.xml -n",

tests/performance/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
require __DIR__ . '/vendor/autoload.php';
5+
require __DIR__ . '/../../vendor/autoload.php';
66

77
// Route to list all available test routes
88
Flight::route('GET /', function () {

tests/performance/performance_tests.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
# Allow URL to be set via environment variable or first command-line argument, default to localhost for safety
4-
URL="${URL:-${1:-http://localhost:8080/test-static}}"
4+
URL="${URL:-${1:-http://localhost:8077/test-static}}"
55
REQUESTS=1000
66
CONCURRENCY=10
77
ITERATIONS=10
@@ -24,15 +24,20 @@ echo "----------------------------------------"
2424

2525
for i in $(seq 1 $ITERATIONS); do
2626
printf "Run %2d/%d: " $i $ITERATIONS
27-
27+
2828
# Run ab and extract time per request
2929
result=$(ab -n $REQUESTS -c $CONCURRENCY $URL 2>/dev/null)
3030
time_per_request=$(echo "$result" | grep "Time per request:" | head -1 | awk '{print $4}')
3131
requests_per_sec=$(echo "$result" | grep "Requests per second:" | awk '{print $4}')
32-
32+
33+
if [[ -z "$time_per_request" || ! "$time_per_request" =~ ^[0-9.]+$ ]]; then
34+
echo "Warning: Could not parse time per request (ab output may be malformed)"
35+
continue
36+
fi
37+
3338
times+=($time_per_request)
3439
total=$(echo "$total + $time_per_request" | bc -l)
35-
40+
3641
printf "%.3f ms (%.2f req/s)\n" $time_per_request $requests_per_sec
3742
done
3843

0 commit comments

Comments
 (0)