Comprehensive benchmarking suite for comparing HTTP client libraries, with a focus on CycleTLS performance.
- 12 HTTP Libraries Tested: cycletls, curl_cffi, tls_client, primp, hrequests, requests, httpx, aiohttp, niquests, pycurl, rnet
- Multiple Test Modes: Synchronous, asynchronous, with/without session reuse
- Payload Size Variations: Test with different response sizes (20KB, 50KB, 200KB)
- Professional Visualizations: Matplotlib-generated comparison charts
- Detailed Metrics: Wall time, CPU time, requests per second
- Flexible Configuration: Command-line arguments for all options
Install the benchmark dependencies:
pip install -e '.[benchmark]'Or with poetry:
poetry install -E benchmarkTest all synchronous HTTP libraries:
python benchmarks/bench.pyWith custom URL and request count:
python benchmarks/bench.py --url http://example.com --repetitions 10000With different payload sizes:
python benchmarks/bench.py \
--url-small http://example.com/20k \
--url-medium http://example.com/50k \
--url-large http://example.com/200k \
--repetitions 10000Test all async-capable HTTP libraries:
python benchmarks/bench_async.pyInclude synchronous baseline for comparison:
python benchmarks/bench_async.py --include-sync-baselinepython benchmarks/bench.py --libraries cycletls requests httpx
python benchmarks/bench_async.py --libraries cycletls aiohttp httpx--url URL Base URL to test (default: http://localhost:5001/)
--url-small URL URL for small payload (~20KB)
--url-medium URL URL for medium payload (~50KB)
--url-large URL URL for large payload (~200KB)
--repetitions, -r N Number of requests per test (default: 10000)
--output, -o FILE Output CSV filename (default: benchmark_results.csv)
--chart, -c FILE Output chart filename (default: benchmark_results.jpg)
--cycletls-chart FILE CycleTLS comparison chart filename
--no-visualization Skip generating charts
--libraries LIB [LIB...] Test only specific libraries
--include-sync-baseline Include synchronous CycleTLS baseline for comparison
The benchmark generates a CSV file with the following columns:
library: Library name (e.g., "cycletls", "requests", "httpx")version: Library versionsession_type: Test type (sync_session, sync_no_session, async_session, async_no_session)payload_size: Response size tested (20k, 50k, 200k, or default)requests: Number of requests madewall_time: Total wall clock time in secondscpu_time: Total CPU time in secondsreq_per_sec: Requests per second (throughput)
Two types of charts are generated:
- Main Results Chart: Grouped bar chart showing all libraries across different payload sizes and session types
- CycleTLS Comparison Chart: Focused comparison highlighting CycleTLS performance vs other libraries
benchmarks/
├── __init__.py # Package initialization
├── core.py # Test execution logic and utilities
├── chart.py # Visualization functions
├── bench.py # Synchronous benchmark orchestrator
├── bench_async.py # Asynchronous benchmark orchestrator
└── README.md # This file
core.py
PycurlSession: Session wrapper for pycurlsession_get_test(): Test with session reusenon_session_get_test(): Test without session reuseasync_session_get_test(): Async test with session reuseasync_non_session_get_test(): Async test without session reuserun_sync_tests(): Run all synchronous benchmarksrun_async_tests(): Run all asynchronous benchmarks
chart.py
plot_benchmark_multi(): Generate comprehensive comparison chartsplot_comparison_chart(): Simple metric comparisonplot_cycletls_focus(): CycleTLS-focused visualization
bench.py
- Main synchronous benchmark orchestrator
- Tests: requests, httpx, niquests, curl_cffi, tls_client, rnet, pycurl, cycletls
bench_async.py
- Main asynchronous benchmark orchestrator
- Tests: httpx, aiohttp, curl_cffi, rnet, ry, cycletls
- cycletls - Advanced TLS fingerprinting with JA3/JA4/HTTP3 support
- curl_cffi - Python bindings to curl-impersonate with TLS fingerprinting
- tls_client - Go-based TLS fingerprinting HTTP client
- primp - Rust-based (rquest) with JA3/JA4 fingerprinting
- hrequests - TLS fingerprinting with browser automation capability
- requests - The classic HTTP library for Python
- httpx - Modern HTTP client with sync/async support
- niquests - High-performance requests alternative
- rnet - Rust-based HTTP client
- pycurl - Python interface to libcurl
- cycletls - CycleTLS async mode (best performance)
- primp - Rust-based async with JA3/JA4 support
- curl_cffi - Async-capable curl-impersonate bindings
- httpx - Modern async HTTP client
- aiohttp - Asynchronous HTTP client/server framework
- rnet - Rust-based async HTTP client
Test CycleTLS against popular libraries:
python benchmarks/bench.py \
--libraries cycletls requests httpx \
--url http://example.com \
--repetitions 1000 \
--output quick_comparison.csvFull async benchmark with all payload sizes:
python benchmarks/bench_async.py \
--url-small https://httpbin.org/bytes/20480 \
--url-medium https://httpbin.org/bytes/51200 \
--url-large https://httpbin.org/bytes/204800 \
--repetitions 5000 \
--output async_full_results.csv \
--chart async_comparison.jpgBenchmark CycleTLS with sync baseline:
python benchmarks/bench_async.py \
--libraries cycletls \
--include-sync-baseline \
--repetitions 10000 \
--output cycletls_performance.csv- Request Count: Use 10,000+ requests for reliable statistics
- Warm-up: Run benchmarks multiple times and average results
- Network: Test against local server for consistent results
- Payload Sizes: Test multiple sizes to see performance across scenarios
- Session Reuse: Compare session vs non-session to measure connection overhead
This benchmark suite is inspired by and compatible with the rnet Python benchmarks, with these differences:
- Default 10,000 requests vs rnet's 400 (for better statistical significance)
- No built-in test server (test against any URL you provide)
- No threading tests (focused on sync/async comparison)
- CycleTLS integration as the primary focus library
- Modular structure for easy extension and customization
If you see import errors, ensure all dependencies are installed:
pip install -e '.[benchmark]'The benchmark will continue with available libraries if some are missing. Install individual libraries as needed:
pip install requests httpx aiohttp curl-cffi niquests pycurl tls-client ry rnetIf chart generation fails, install visualization dependencies:
pip install matplotlib pandas seabornOn macOS, pycurl may require additional setup:
brew install curl
pip install --no-cache-dir pycurlTo add a new library to the benchmarks:
- Add the library to
pyproject.tomlunder[project.optional-dependencies].benchmark - Add import logic in
bench.pyorbench_async.pyimport_libraries()function - Create a session wrapper if needed (see
PycurlSessionexample) - Test with
--libraries your_library
MIT - Same as CycleTLS main project