Skip to content

Commit a1ef3f6

Browse files
committed
feat: Initial Commit
0 parents  commit a1ef3f6

23 files changed

+900
-0
lines changed

.gitignore

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
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+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
#Pipfile.lock
93+
94+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95+
__pypackages__/
96+
97+
# Celery stuff
98+
celerybeat-schedule
99+
celerybeat.pid
100+
101+
# SageMath parsed files
102+
*.sage.py
103+
104+
# Environments
105+
.env
106+
.venv
107+
env/
108+
venv/
109+
ENV/
110+
env.bak/
111+
venv.bak/
112+
113+
# Spyder project settings
114+
.spyderproject
115+
.spyproject
116+
117+
# Rope project settings
118+
.ropeproject
119+
120+
# mkdocs documentation
121+
/site
122+
123+
# mypy
124+
.mypy_cache/
125+
.dmypy.json
126+
dmypy.json
127+
128+
# Pyre type checker
129+
.pyre/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 ⟠ Rodolfo De Nadai
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

benchmark.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
FULL_REPORT=README.md
4+
rm ${FULL_REPORT}
5+
6+
docker-compose down
7+
docker-compose up --build -d
8+
9+
sleep 2
10+
11+
cat template.md >> ${FULL_REPORT}
12+
echo "" >> ${FULL_REPORT}
13+
echo "> Last run: $(date)" >> ${FULL_REPORT}
14+
for FILE in $(find report/markdown -name "*.md" | sort -V)
15+
do
16+
NAME=$(basename -- ${FILE} .md)
17+
echo "" >> ${FULL_REPORT}
18+
cat ${FILE} >> ${FULL_REPORT}
19+
echo "" >> ${FULL_REPORT}
20+
done
21+
22+
sleep 2
23+
24+
# Clean Up
25+
docker-compose down
26+
docker system prune -f

docker-compose.yml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
version: "3"
2+
3+
services:
4+
python36:
5+
build:
6+
context: ./docker/
7+
args:
8+
DOCKER_IMAGE: python:3.6.15-slim-buster
9+
SETUPTOOLS_VERSION: 59.6.0
10+
REQUIREMENTS: requirements36.txt
11+
entrypoint: ./entrypoint.sh
12+
# tty: true
13+
# stdin_open: true
14+
environment:
15+
- PY_VERSION=3.6
16+
volumes:
17+
- ./src:/code/src
18+
- ./report:/code/report
19+
python37:
20+
build:
21+
context: ./docker/
22+
args:
23+
DOCKER_IMAGE: python:3.7.15-slim-buster
24+
REQUIREMENTS: requirements37.txt
25+
entrypoint: ./entrypoint.sh
26+
environment:
27+
- PY_VERSION=3.7
28+
volumes:
29+
- ./src:/code/src
30+
- ./report:/code/report
31+
depends_on:
32+
python36:
33+
condition: service_completed_successfully
34+
python38:
35+
build:
36+
context: ./docker/
37+
args:
38+
DOCKER_IMAGE: python:3.8.15-slim-buster
39+
entrypoint: ./entrypoint.sh
40+
environment:
41+
- PY_VERSION=3.8
42+
volumes:
43+
- ./src:/code/src
44+
- ./report:/code/report
45+
depends_on:
46+
python37:
47+
condition: service_completed_successfully
48+
python39:
49+
build:
50+
context: ./docker/
51+
args:
52+
DOCKER_IMAGE: python:3.9.15-slim-buster
53+
entrypoint: ./entrypoint.sh
54+
environment:
55+
- PY_VERSION=3.9
56+
volumes:
57+
- ./src:/code/src
58+
- ./report:/code/report
59+
depends_on:
60+
python38:
61+
condition: service_completed_successfully
62+
python310:
63+
build:
64+
context: ./docker/
65+
args:
66+
DOCKER_IMAGE: python:3.10.8-slim-buster
67+
entrypoint: ./entrypoint.sh
68+
environment:
69+
- PY_VERSION=3.10
70+
volumes:
71+
- ./src:/code/src
72+
- ./report:/code/report
73+
depends_on:
74+
python39:
75+
condition: service_completed_successfully
76+
python311:
77+
build:
78+
context: ./docker/
79+
args:
80+
DOCKER_IMAGE: python:3.11.0-slim-buster
81+
entrypoint: ./entrypoint.sh
82+
environment:
83+
- PY_VERSION=3.11
84+
volumes:
85+
- ./src:/code/src
86+
- ./report:/code/report
87+
depends_on:
88+
python310:
89+
condition: service_completed_successfully

docker/Dockerfile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
ARG DOCKER_IMAGE=python:3.6.15-slim-buster
2+
3+
FROM $DOCKER_IMAGE
4+
5+
SHELL ["/bin/bash", "-o", "pipefail", "-e", "-u", "-x", "-c"]
6+
7+
WORKDIR /code
8+
9+
RUN apt-get install -y tzdata
10+
11+
ENV DEBIAN_FRONTEND=noninteractive \
12+
LANGUAGE=C.UTF-8 \
13+
ANG=C.UTF-8 \
14+
LC_ALL=C.UTF-8 \
15+
LC_CTYPE=C.UTF-8 \
16+
LC_MESSAGES=C.UTF-8 \
17+
PYTHONDONTWRITEBYTECODE=1 \
18+
PYTHONUNBUFFERED=1 \
19+
TZ=America/Sao_Paulo
20+
21+
RUN apt-get update && \
22+
# Timezone
23+
apt-get install -y tzdata && \
24+
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
25+
apt-get update && \
26+
apt install -y --no-install-recommends \
27+
dumb-init gcc make build-essential wget curl \
28+
libpq-dev libssl-dev zlib1g-dev \
29+
libbz2-dev libreadline-dev libsqlite3-dev \
30+
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev && \
31+
apt-get clean && rm -rf /var/lib/apt/lists/*
32+
33+
RUN wget https://github.com/sharkdp/hyperfine/releases/download/v1.15.0/hyperfine_1.15.0_amd64.deb && \
34+
dpkg -i hyperfine_1.15.0_amd64.deb && \
35+
rm hyperfine_1.15.0_amd64.deb
36+
37+
ARG SETUPTOOLS_VERSION=65.6.0
38+
ARG REQUIREMENTS=requirements.txt
39+
40+
COPY ./${REQUIREMENTS} .
41+
COPY ./requirements-internal.txt .
42+
43+
RUN pip install pip setuptools==${SETUPTOOLS_VERSION} --upgrade && \
44+
pip install --no-cache-dir -r ${REQUIREMENTS} && \
45+
pip install --no-cache-dir -r requirements-internal.txt
46+
47+
COPY ./entrypoint.sh .
48+
49+
COPY ./report.py .
50+
51+
ENTRYPOINT ["dumb-init", "--"]
52+
CMD ["tail", "-f", "/dev/null"]

docker/entrypoint.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
3+
i=0
4+
for FILE in $(find src/ -name "*.py")
5+
do
6+
echo "--------------------"
7+
echo "Running $FILE"
8+
9+
DONT_RUN=$(grep -rnw "${FILE}" -e "@DONT_RUN")
10+
ALLOWED_PYTHON=$(grep -rnw "${FILE}" -e "@ALLOWED_VERSIONS")
11+
ALLOWED_PYTHON_VERSION=$(echo $ALLOWED_PYTHON | grep "${PY_VERSION}")
12+
MPROF_INTERVAL=$(cat ${FILE} | grep -e "@MPROF_INTERVAL" | sed 's/# @MPROF_INTERVAL: //')
13+
MPROF_INTERVAL=${MPROF_INTERVAL:="0.01"}
14+
MPROF_MULTIPROCESS=$(cat ${FILE} | grep -e "@MPROF_MULTIPROCESS" | sed 's/# @MPROF_MULTIPROCESS: //')
15+
MPROF_MULTIPROCESS=${MPROF_MULTIPROCESS:="-C"}
16+
echo "MPROF_INTERVAL: $MPROF_INTERVAL"
17+
echo "MPROF_MULTIPROCESS: $MPROF_MULTIPROCESS"
18+
19+
if [ -z "$DONT_RUN" ]
20+
then
21+
if [ -z "$ALLOWED_PYTHON" ] || [ -z "$ALLOWED_PYTHON_VERSION" ]
22+
then
23+
echo "Python ${PY_VERSION} version not allowed in $FILE"
24+
echo "{\"results\": [{\"command\": \"${FILE}\"}]}" > report/tmp/${i}part_${PY_VERSION}.json
25+
else
26+
# Performance
27+
hyperfine --show-output --export-json report/tmp/${i}part_${PY_VERSION}.json --runs 5 --warmup 3 "python ${FILE}"
28+
# Memory
29+
for k in 1 2 3; do
30+
mprof run ${MPROF_MULTIPROCESS} -T ${MPROF_INTERVAL} -o report/tmp/${i}_${k}part_${PY_VERSION}.dat ${FILE} &
31+
done
32+
wait
33+
echo "${FILE}" >> report/tmp/${i}part_${PY_VERSION}_full.txt
34+
for k in 1 2 3; do
35+
cat report/tmp/${i}_${k}part_${PY_VERSION}.dat | sed '/^CHLD/ d' > report/tmp/${i}_${k}part_${PY_VERSION}_parcial.dat
36+
mv report/tmp/${i}_${k}part_${PY_VERSION}_parcial.dat report/tmp/${i}_${k}part_${PY_VERSION}.dat
37+
cat report/tmp/${i}_${k}part_${PY_VERSION}.dat | tail -1 >> report/tmp/${i}part_${PY_VERSION}_full.txt
38+
done
39+
mprof clean
40+
fi
41+
((i=i+1))
42+
else
43+
echo "Skipping $FILE"
44+
fi
45+
done
46+
47+
python -m report ${PY_VERSION}
48+
rm report/tmp/*.json
49+
rm report/tmp/*.dat
50+
rm report/tmp/*.txt
51+
sleep 2

0 commit comments

Comments
 (0)