Skip to content

Commit 70c0bbe

Browse files
authored
Merge branch 'master' into update-perf-bench
2 parents 53a7ea9 + afe075c commit 70c0bbe

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ exclude .circleci
1414
exclude .circleci/config.yml
1515
exclude codecov.yml
1616
exclude .mypy.ini
17+
exclude profiler.py
1718

1819
include LICENSE
1920
include LICENSE.markdown-it

profiler.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""A script for profiling.
2+
3+
To generate and read results:
4+
- `tox -e profile`
5+
- `firefox .tox/prof/output.svg`
6+
"""
7+
from pathlib import Path
8+
9+
from markdown_it import MarkdownIt
10+
11+
commonmark_spec = (
12+
(Path(__file__).parent / "tests" / "test_cmark_spec" / "spec.md")
13+
.read_bytes()
14+
.decode()
15+
)
16+
17+
# Run this a few times to emphasize over imports and other overhead above
18+
for _ in range(10):
19+
MarkdownIt().render(commonmark_spec)

setup.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ benchmarking =
7070
psutil
7171
pytest
7272
pytest-benchmark~=3.2
73+
profiling =
74+
gprof2dot
7375

7476
[options.packages.find]
7577
exclude =

tox.ini

+13
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,16 @@ setenv =
4343
commands =
4444
clean: rm -rf docs/_build
4545
sphinx-build -nW --keep-going -b {posargs:html} docs/ docs/_build/{posargs:html}
46+
47+
[testenv:profile]
48+
description = run profiler (use e.g. `firefox .tox/prof/output.svg` to open)
49+
extras = profiling
50+
allowlist_externals =
51+
mkdir
52+
dot
53+
commands =
54+
mkdir -p "{toxworkdir}/prof"
55+
python -m cProfile -o "{toxworkdir}/prof/output.pstats" profiler.py
56+
gprof2dot -f pstats -o "{toxworkdir}/prof/output.dot" "{toxworkdir}/prof/output.pstats"
57+
dot -Tsvg -o "{toxworkdir}/prof/output.svg" "{toxworkdir}/prof/output.dot"
58+
python -c 'import pathlib; print("profiler svg output under file://\{0\}".format(pathlib.Path(r"{toxworkdir}") / "prof" / "output.svg"))'

0 commit comments

Comments
 (0)