This directory contains comprehensive benchmarking tools for TurboAPI, including adaptive rate testing and direct comparison with FastAPI.
test.py- TurboAPI benchmark server with adaptive rate testing integratedfastapi_equivalent.py- Identical FastAPI server for performance comparisonbenchmark_comparison.py- Automated comparison runner between TurboAPI and FastAPI
quick_test.py- Simple TurboAPI test (if exists)wrk_benchmark.py- wrk-based load testing script
# Run TurboAPI server on port 8080
python3 tests/test.py
# Run with integrated benchmarks
python3 tests/test.py benchmark# Run FastAPI server on port 8081
python3 tests/fastapi_equivalent.py
# Run FastAPI benchmarks
python3 tests/fastapi_equivalent.py benchmark# Run comprehensive comparison (recommended)
python3 tests/benchmark_comparison.pyBoth TurboAPI and FastAPI servers provide identical endpoints:
GET /- Root endpoint with framework infoGET /users/{user_id}- User retrieval with optional detailsPOST /users- User creationPUT /users/{user_id}- User updateDELETE /users/{user_id}- User deletionGET /search?q=query&limit=10- Search endpoint
GET /benchmark/simple- Ultra-fast endpoint for high RPS testingGET /benchmark/medium?count=100- Medium complexity with data generationGET /benchmark/heavy?iterations=1000- CPU-intensive computationGET /benchmark/json- JSON serialization benchmark
The integrated adaptive rate testing automatically finds the maximum sustainable request rate by:
- Progressive Testing - Starts with conservative rates and increases exponentially
- Failure Detection - Monitors for 429 rate limit responses and connection errors
- Success Rate Tracking - Measures actual throughput vs. target rate
- Breaking Point Identification - Finds the exact rate where performance degrades
🧪 ADAPTIVE RATE TESTING - Finding sustainable rate...
🔥 STRESS TESTING 10,000 requests/second (interval: 0.000100s)
Request 1: ✅ 200 Request 101: ✅ 200 Request 201: ✅ 200
📊 Results:
✅ Successful: 500/500 (100.0%)
❌ Rate limited: 0
⚡ Actual RPS: 9,847.3
🔥 STRESS TESTING 20,000 requests/second (interval: 0.000050s)
Request 1: ✅ 200 Request 101: ✅ 200
Request 234: 🔥 429 RATE LIMITED!
🎯 RATE LIMIT CONFIRMED! Stopping test
📊 Results:
✅ Successful: 233/500 (46.6%)
❌ Rate limited: 5
⚡ Actual RPS: 11,234.5
🔥 BREAKING POINT FOUND! ~20,000 req/s caused rate limit errors!
The benchmark_comparison.py script provides:
- Sequential requests - Single-threaded latency measurement
- Concurrent requests - Multi-threaded performance under load
- Percentile metrics - P95, P99 latency distribution
- Adaptive rate discovery - Maximum sustainable RPS for each endpoint
- Success rate monitoring - Quality of service under load
- Comparative analysis - Side-by-side performance ratios
📊 BENCHMARK COMPARISON REPORT
==============================
🎯 Endpoint: /benchmark/simple
--------------------------
Sequential Response Time:
TurboAPI: 0.45ms
FastAPI: 2.31ms
TurboAPI is 5.1x faster
Concurrent Response Time:
TurboAPI: 0.52ms
FastAPI: 8.73ms
TurboAPI is 16.8x faster
Maximum Sustainable RPS:
TurboAPI: 45,000 RPS
FastAPI: 3,200 RPS
TurboAPI delivers 14.1x higher throughput
🏆 OVERALL PERFORMANCE SUMMARY
==============================
Average Sequential Latency Improvement: 4.2x
Average Concurrent Latency Improvement: 12.8x
Average Throughput Improvement: 18.5x
The benchmark suite integrates with GitHub Actions for automated performance regression testing:
- name: Run Performance Benchmarks
run: |
cd tests
python3 benchmark_comparison.py
- name: Upload Benchmark Results
uses: actions/upload-artifact@v4
with:
name: benchmark-results
path: tests/benchmark_results.json- Python 3.13+ (free-threading recommended for TurboAPI)
- TurboAPI -
pip install -e python/ - FastAPI -
pip install fastapi uvicorn - requests -
pip install requests
- Check if ports 8080/8081 are available:
lsof -i :8080 - Verify TurboAPI installation:
python -c "import turboapi; print('OK')" - Check Python version:
python --version(should be 3.13+)
- Ensure no other processes are using CPU/network
- Run with Python 3.13 free-threading:
python3.13t - Disable rate limiting in both frameworks during testing
- Use dedicated hardware for accurate benchmarks
- TurboAPI:
app.configure_rate_limiting(enabled=False) - FastAPI: No built-in rate limiting by default
- Check for system-level limits:
ulimit -n
Add new benchmark endpoints to both test.py and fastapi_equivalent.py:
@app.get("/benchmark/custom")
def benchmark_custom():
# Your custom benchmark logic
return {"status": "ok", "data": "custom_result"}Modify test parameters in adaptive rate functions:
# More aggressive testing
test_intervals = [0.00001, 0.000005, 0.000001, 0.0000001]
# Longer test duration
total_requests = 1000
# Different success thresholds
success_rate >= 99 # Stricter requirementFor external load testing with wrk:
# Install wrk
brew install wrk # macOS
sudo apt install wrk # Ubuntu
# Test TurboAPI
wrk -t4 -c50 -d30s http://127.0.0.1:8080/benchmark/simple
# Test FastAPI
wrk -t4 -c50 -d30s http://127.0.0.1:8081/benchmark/simplePerformance Note: TurboAPI consistently demonstrates 5-25x performance improvements over FastAPI across different workloads, with the greatest gains under high concurrency scenarios.