← back to Watches
benchmark.sh
100 lines
#!/bin/bash
# Omega Watch Price History - Performance Benchmark
# Runs comprehensive performance tests and generates report
echo "╔═══════════════════════════════════════════════════════════╗"
echo "║ OMEGA WATCH PRICE HISTORY - PERFORMANCE BENCHMARK ║"
echo "╚═══════════════════════════════════════════════════════════╝"
echo ""
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Check if server is running
echo -e "${BLUE}1. Checking server status...${NC}"
if curl -s http://45.61.58.125:7600/api/health > /dev/null; then
echo -e "${GREEN}✓ Server is running${NC}"
else
echo -e "${RED}✗ Server is not running. Start it with: node server.js${NC}"
exit 1
fi
# Test TTFB
echo -e "\n${BLUE}2. Testing Time to First Byte (TTFB)...${NC}"
TTFB=$(curl -o /dev/null -s -w '%{time_starttransfer}\n' http://45.61.58.125:7600/)
TTFB_MS=$(echo "$TTFB * 1000" | bc)
echo -e " TTFB: ${GREEN}${TTFB_MS}ms${NC}"
# Test API endpoints
echo -e "\n${BLUE}3. Testing API endpoints...${NC}"
test_endpoint() {
local name=$1
local endpoint=$2
local time=$(curl -o /dev/null -s -w '%{time_total}\n' "http://45.61.58.125:7600${endpoint}")
local time_ms=$(echo "$time * 1000" | bc)
echo -e " ${name}: ${GREEN}${time_ms}ms${NC}"
}
test_endpoint "Health Check" "/api/health"
test_endpoint "Watches List" "/api/watches"
test_endpoint "Statistics" "/api/statistics"
test_endpoint "Collections" "/api/collections"
# Test bundle sizes
echo -e "\n${BLUE}4. Analyzing bundle sizes...${NC}"
cd /root/Projects/watches/dist/assets
TOTAL_SIZE=$(du -sh . | awk '{print $1}')
JS_COUNT=$(ls -1 *.js 2>/dev/null | wc -l)
CSS_COUNT=$(ls -1 *.css 2>/dev/null | wc -l)
echo -e " Total bundle size: ${GREEN}${TOTAL_SIZE}${NC}"
echo -e " JavaScript files: ${GREEN}${JS_COUNT}${NC}"
echo -e " CSS files: ${GREEN}${CSS_COUNT}${NC}"
# Test compression
echo -e "\n${BLUE}5. Testing compression...${NC}"
HAS_GZIP=$(curl -s -I -H "Accept-Encoding: gzip" http://45.61.58.125:7600/ | grep -i "content-encoding: gzip" && echo "YES" || echo "NO")
echo -e " Gzip compression: ${GREEN}${HAS_GZIP}${NC}"
# Test caching headers
echo -e "\n${BLUE}6. Testing cache headers...${NC}"
CACHE_CONTROL=$(curl -s -I http://45.61.58.125:7600/ | grep -i "cache-control" | cut -d: -f2-)
echo -e " HTML Cache-Control:${GREEN}${CACHE_CONTROL}${NC}"
API_CACHE=$(curl -s -I http://45.61.58.125:7600/api/watches | grep -i "cache-control" | cut -d: -f2-)
echo -e " API Cache-Control:${GREEN}${API_CACHE}${NC}"
# Concurrent load test
echo -e "\n${BLUE}7. Running concurrent load test (20 requests)...${NC}"
START=$(date +%s.%N)
for i in {1..20}; do
curl -s http://45.61.58.125:7600/api/watches > /dev/null &
done
wait
END=$(date +%s.%N)
DURATION=$(echo "$END - $START" | bc)
RPS=$(echo "20 / $DURATION" | bc -l | xargs printf "%.2f")
echo -e " Total time: ${GREEN}${DURATION}s${NC}"
echo -e " Requests/sec: ${GREEN}${RPS}${NC}"
# Run Node.js performance test
echo -e "\n${BLUE}8. Running detailed performance test...${NC}"
cd /root/Projects/watches
node performance-test.js
echo ""
echo "╔═══════════════════════════════════════════════════════════╗"
echo "║ BENCHMARK COMPLETE ║"
echo "╚═══════════════════════════════════════════════════════════╝"
echo ""
echo -e "${GREEN}✓ All tests completed successfully${NC}"
echo -e "\nDetailed results: ${BLUE}/tmp/performance-results.json${NC}"
echo -e "Performance report: ${BLUE}/root/Projects/watches/PERFORMANCE_REPORT.md${NC}"
echo ""