Skip to content

Commit b25ba7e

Browse files
committed
Initial commit
1 parent 1b36129 commit b25ba7e

13 files changed

Lines changed: 4704 additions & 0 deletions

.github/workflows/main.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: cicd
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
code-scan:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
strategy:
13+
matrix:
14+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
24+
- name: Install dependencies
25+
run: pip install --no-cache-dir -U pip ruff
26+
27+
- name: Lint and security check with Ruff
28+
run: ruff check
29+
30+
- name: Check code formatting with Ruff
31+
run: ruff format --check

.gitignore

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
# *.mo
56+
# *.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# UV
98+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
#uv.lock
102+
103+
# poetry
104+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105+
# This is especially recommended for binary packages to ensure reproducibility, and is more
106+
# commonly ignored for libraries.
107+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108+
#poetry.lock
109+
110+
# pdm
111+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112+
#pdm.lock
113+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114+
# in version control.
115+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116+
.pdm.toml
117+
.pdm-python
118+
.pdm-build/
119+
120+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121+
__pypackages__/
122+
123+
# Celery stuff
124+
celerybeat-schedule
125+
celerybeat.pid
126+
127+
# SageMath parsed files
128+
*.sage.py
129+
130+
# Environments
131+
.env
132+
.venv
133+
env/
134+
venv/
135+
ENV/
136+
env.bak/
137+
venv.bak/
138+
139+
# Spyder project settings
140+
.spyderproject
141+
.spyproject
142+
143+
# Rope project settings
144+
.ropeproject
145+
146+
# mkdocs documentation
147+
/site
148+
149+
# mypy
150+
.mypy_cache/
151+
.dmypy.json
152+
dmypy.json
153+
154+
# Pyre type checker
155+
.pyre/
156+
157+
# pytype static type analyzer
158+
.pytype/
159+
160+
# Cython debug symbols
161+
cython_debug/
162+
163+
# PyCharm
164+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166+
# and can be added to the global gitignore or merged into this file. For a more nuclear
167+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
168+
#.idea/
169+
170+
# PyPI configuration file
171+
.pypirc
172+
173+
174+
.vscode
175+
.ruff_cache
176+
177+
outputs/*.html
178+
!outputs/*example.html

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
repos:
2+
- repo: https://github.com/charliermarsh/ruff-pre-commit
3+
rev: v0.14.0
4+
hooks:
5+
- id: ruff-check
6+
args: [--fix]
7+
- id: ruff-format

README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# 🏎️ Benchmark for pyproxy
2+
3+
This benchmarking tool is designed to measure the performance of **pyproxy** in handling HTTP and HTTPS requests. It allows you to compare the average, maximum, and minimum request times both with and without the proxy.
4+
5+
---
6+
7+
## 📦 **Installation**
8+
9+
### Install dependencies
10+
Before running the benchmark, you need to install the required dependencies. You can do so by running the following command:
11+
```bash
12+
pip install -r benchmark/requirements.txt
13+
```
14+
15+
---
16+
17+
## 🚀 **Usage**
18+
19+
### Start the Proxy
20+
Before running the benchmark, ensure that **pyproxy** is running. Start the proxy by running:
21+
```bash
22+
python3 -m pyproxy
23+
```
24+
The proxy will be available at `0.0.0.0:8080`.
25+
26+
### Run the benchmark
27+
Once the proxy is up and running, execute the following command from the root of the project to start the benchmark:
28+
```bash
29+
python3 benchmark/benchmark.py --target-file benchmark/urls.txt
30+
```
31+
32+
This will run the benchmark using the URLs listed in `benchmark/urls.txt` and generate a report on the request times, comparing the proxy performance (with and without the proxy).
33+
34+
### Customizing the URLs and Requests
35+
36+
- You can modify the `benchmark/urls.txt` file to add multiple URLs that you want to benchmark. Each line should contain a URL.
37+
38+
- Alternatively, you can test a single URL by using the `--target-url` argument. For example:
39+
```bash
40+
python3 benchmark/benchmark.py --target-url http://example.com
41+
```
42+
43+
- You can also change the number of requests made during the benchmark using the `--num-requests` argument. By default, it tests 100 requests per URL, but you can adjust it like this:
44+
```bash
45+
python3 benchmark/benchmark.py --target-file benchmark/urls.txt --num-requests 50
46+
```
47+
This will test 50 requests per URL instead of the default 10.
48+
49+
---
50+
51+
## 📊 **Benchmark Results**
52+
53+
The benchmarking script will produce a table comparing the average, maximum, and minimum request times for each URL, as well as a breakdown into the following columns:
54+
55+
- **With Proxy**:
56+
- **Avg**: Average request time with the proxy.
57+
- **Max**: Maximum request time with the proxy.
58+
- **Min**: Minimum request time with the proxy.
59+
60+
- **Without Proxy**:
61+
- **Avg**: Average request time without the proxy.
62+
- **Max**: Maximum request time without the proxy.
63+
- **Min**: Minimum request time without the proxy.
64+
65+
The detailed report will be available in the `outputs` directory as a file named `benchmark_combined_report_<timestamp>.html`. You can open this HTML file in a browser to view the results.
66+
67+
## 📈 **Example Benchmark Results**
68+
69+
### Global Proxy Performance Summary
70+
71+
| **Metric** | **Value** |
72+
|--------------------------------------|--------------------|
73+
| Global average without proxy | 0.341067 seconds |
74+
| Global average with proxy | 0.414619 seconds |
75+
| Impact (Slowdown) | 21.57% |
76+
77+
### Benchmark Results Summary
78+
79+
| **URL** | **Avg (s)** | **Min (s)** | **Max (s)** | **Avg with Proxy (s)** | **Min with Proxy (s)** | **Max with Proxy (s)** |
80+
|-----------------------|-------------|-------------|-------------|-------------------------|-------------------------|-------------------------|
81+
| `http://example.com` | 0.24766 | 0.19376 | 0.30262 | 0.27064 | 0.19926 | 0.30419 |
82+
| `https://example.com` | 0.43447 | 0.33968 | 0.48372 | 0.55860 | 0.41271 | 0.67175 |
83+
84+
---
85+
86+
### Example Reports
87+
88+
Example reports can be found in the following files:
89+
- [Interactive Report Example](outputs/benchmark_combined_interactive_example.html)
90+
- [Report Example](outputs/benchmark_combined_report_example.html)
91+
92+
These files contain example benchmark results and interactive graphs.
93+
94+
---

0 commit comments

Comments
 (0)