File tree Expand file tree Collapse file tree 4 files changed +35
-0
lines changed Expand file tree Collapse file tree 4 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ exclude .circleci
1414exclude .circleci/config.yml
1515exclude codecov.yml
1616exclude .mypy.ini
17+ exclude profiler.py
1718
1819include LICENSE
1920include LICENSE.markdown-it
Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff 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]
7577exclude =
Original file line number Diff line number Diff line change @@ -43,3 +43,16 @@ setenv =
4343commands =
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"))'
You can’t perform that action at this time.
0 commit comments