Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exclude .circleci
exclude .circleci/config.yml
exclude codecov.yml
exclude .mypy.ini
exclude profiler.py

include LICENSE
include LICENSE.markdown-it
Expand Down
19 changes: 19 additions & 0 deletions profiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""A script for profiling.

To generate and read results:
- `tox -e profile`
- `firefox .tox/prof/output.svg`
"""
from pathlib import Path

from markdown_it import MarkdownIt

commonmark_spec = (
(Path(__file__).parent / "tests" / "test_cmark_spec" / "spec.md")
.read_bytes()
.decode()
)

# Run this a few times to emphasize over imports and other overhead above
for _ in range(10):
MarkdownIt().render(commonmark_spec)
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ benchmarking =
psutil
pytest
pytest-benchmark~=3.2
profiling =
gprof2dot

[options.packages.find]
exclude =
Expand Down
13 changes: 13 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,16 @@ setenv =
commands =
clean: rm -rf docs/_build
sphinx-build -nW --keep-going -b {posargs:html} docs/ docs/_build/{posargs:html}

[testenv:profile]
description = run profiler (use e.g. `firefox .tox/prof/output.svg` to open)
extras = profiling
allowlist_externals =
mkdir
dot
commands =
mkdir -p "{toxworkdir}/prof"
python -m cProfile -o "{toxworkdir}/prof/output.pstats" profiler.py
gprof2dot -f pstats -o "{toxworkdir}/prof/output.dot" "{toxworkdir}/prof/output.pstats"
dot -Tsvg -o "{toxworkdir}/prof/output.svg" "{toxworkdir}/prof/output.dot"
python -c 'import pathlib; print("profiler svg output under file://\{0\}".format(pathlib.Path(r"{toxworkdir}") / "prof" / "output.svg"))'