Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add benchmark for Docutils
  • Loading branch information
AA-Turner committed Jun 13, 2022
commit 5837ce4cfe74d9fea5806128bb1bbf02254ff3ca
9 changes: 9 additions & 0 deletions doc/benchmarks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@ Pseudo-code of the benchmark::
See the `Dulwich project <https://www.dulwich.io/>`_.



docutils
--------

Use Docutils_ to convert Docutils' documentation to HTML.
Representative of building a medium-sized documentation set.

.. _Docutils: https://docutils.sourceforge.io/

fannkuch
--------

Expand Down
1 change: 1 addition & 0 deletions pyperformance/data-files/benchmarks/MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ deepcopy <local>
deltablue <local>
django_template <local>
dulwich_log <local>
docutils <local>
fannkuch <local>
float <local>
genshi <local>
Expand Down
13 changes: 13 additions & 0 deletions pyperformance/data-files/benchmarks/bm_docutils/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[project]
name = "pyperformance_bm_docutils"
requires-python = ">=3.8"
dependencies = [
"pyperf",
"docutils",
]
urls.repository = "https://github.com/python/pyperformance"
dynamic = ["version"]

[tool.pyperformance]
name = "docutils"
tags = "apps"
49 changes: 49 additions & 0 deletions pyperformance/data-files/benchmarks/bm_docutils/run_benchmark.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""
Convert Docutils' documentation from reStructuredText to <format>.
"""

from pathlib import Path
import shutil

import docutils
from docutils import core
import pyperf


def build_html(doc_root, out_root):
for file in doc_root.rglob("*.txt"):
try:
dest = out_root / file.relative_to(doc_root).with_suffix(".html")
dest.mkdir(parents=True, exist_ok=True)
core.publish_file(source_path=str(file),
Comment thread
AA-Turner marked this conversation as resolved.
Outdated
destination_path=str(dest),
reader_name="standalone",
parser_name="restructuredtext",
writer_name="html5")
except docutils.ApplicationError:
...


def bench_docutils(loops, doc_root, out_root):
runs = []

for _ in range(loops):
t0 = pyperf.perf_counter()
build_html(doc_root, out_root)
runs.append(pyperf.perf_counter() - t0)

shutil.rmtree(out_root, ignore_errors=True)

return sum(runs)


if __name__ == "__main__":
runner = pyperf.Runner()

runner.metadata['description'] = "Render documentation with Docutils"
args = runner.parse_args()

DOC_ROOT = Path("data/docs").resolve()
OUT_ROOT = Path("data/out").resolve()

runner.bench_time_func("docutils", bench_docutils, DOC_ROOT, OUT_ROOT)