File tree 4 files changed +35
-0
lines changed
4 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ exclude .circleci
14
14
exclude .circleci/config.yml
15
15
exclude codecov.yml
16
16
exclude .mypy.ini
17
+ exclude profiler.py
17
18
18
19
include LICENSE
19
20
include 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 =
70
70
psutil
71
71
pytest
72
72
pytest-benchmark~=3.2
73
+ profiling =
74
+ gprof2dot
73
75
74
76
[options.packages.find]
75
77
exclude =
Original file line number Diff line number Diff line change @@ -43,3 +43,16 @@ setenv =
43
43
commands =
44
44
clean: rm -rf docs/_build
45
45
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