Skip to content

Commit f5ceb57

Browse files
committed
Update benchmarks, add just command & comments
1 parent 3652e62 commit f5ceb57

File tree

9 files changed

+99
-143
lines changed

9 files changed

+99
-143
lines changed

python/benchmarks/bench_attrs.py

Lines changed: 43 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -13,71 +13,56 @@
1313
# limitations under the License.
1414

1515
import attrs
16-
from attrs import define, field
17-
18-
19-
REPEAT = 100_000
20-
URL = "http://www.lrec-conf.org/proceedings/lrec2000/pdf/374.pdf"
21-
22-
23-
class UrlWithoutAttrs:
24-
def __init__(self, url: str) -> None:
25-
self.url = url
26-
27-
28-
@define
29-
class UrlWithoutValidation:
30-
url: str
31-
32-
33-
@define
34-
class UrlWithValidation:
35-
url: str = field()
36-
37-
@url.validator
38-
def noop(self, _attribute, _value):
39-
pass
40-
41-
42-
def vanilla_class_without_validation():
43-
"""Instantiate a regular class."""
16+
from pathlib import Path
17+
18+
from acl_anthology.collections import Collection, Volume
19+
from acl_anthology.people import NameSpecification as NameSpec
20+
from acl_anthology.text import MarkupText
21+
22+
23+
REPEAT = 1_000
24+
25+
26+
def create_volume():
27+
volume_title = MarkupText.from_string("Lorem ipsum")
28+
volume_shorttitle = MarkupText.from_string("L.I.")
29+
parent = Collection("2023.acl", None, Path("."))
30+
volume = Volume(
31+
id="long",
32+
parent=parent,
33+
type="proceedings",
34+
booktitle=volume_title,
35+
year="2023",
36+
address="Online",
37+
doi="10.100/0000",
38+
editors=[NameSpec("Bollmann, Marcel")],
39+
ingest_date="2023-01-12",
40+
isbn="0000-0000-0000",
41+
month="jan",
42+
pdf=None,
43+
publisher="Myself",
44+
shortbooktitle=volume_shorttitle,
45+
venue_ids=["li", "acl"],
46+
)
47+
48+
49+
def instantiate_volume_regularly():
50+
"""Instantiate a Volume."""
4451
for _ in range(REPEAT):
45-
UrlWithoutAttrs(URL)
52+
create_volume()
4653

4754

48-
def attrs_class_without_validation():
49-
"""Instantiate a class without attribute validation."""
55+
def instantiate_volume_without_validation():
56+
"""Instantiate a class with attribute validation disabled."""
5057
for _ in range(REPEAT):
51-
UrlWithoutValidation(URL)
52-
53-
54-
def attrs_class_with_validation():
55-
"""Instantiate a class with attribute validation."""
56-
for _ in range(REPEAT):
57-
UrlWithValidation(URL)
58-
59-
60-
def attrs_class_with_validation_disabled():
61-
"""Instantiate a class that has attribute validation, but disabled."""
62-
with attrs.validators.disabled():
63-
for _ in range(REPEAT):
64-
UrlWithValidation(URL)
58+
with attrs.validators.disabled():
59+
create_volume()
6560

6661

6762
__benchmarks__ = [
6863
(
69-
vanilla_class_without_validation,
70-
attrs_class_without_validation,
71-
"attrs: Vanilla class vs. attrs class",
72-
),
73-
(
74-
attrs_class_with_validation,
75-
attrs_class_without_validation,
76-
"attrs: Attribute validation vs. no validation",
77-
),
78-
(
79-
attrs_class_with_validation_disabled,
80-
attrs_class_without_validation,
81-
"attrs: Attribute validation disabled vs. no validation",
64+
instantiate_volume_regularly,
65+
instantiate_volume_without_validation,
66+
"attrs: instantiate Volume with attrs.validators.disabled",
8267
),
8368
]

python/benchmarks/bench_sanitycheck.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

python/benchmarks/bench_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ def detect_url_startswith_protocol():
5050
(
5151
detect_url_regex,
5252
detect_url_contains_separator,
53-
"Check URL via regex vs. '://' in string",
53+
"Check URL via '://' in string instead of regex",
5454
),
5555
(
5656
detect_url_startswith_protocol,
5757
detect_url_contains_separator,
58-
"Check URL via .startswith('http') vs. '://' in string",
58+
"Check URL via '://' in string instead of .startswith('http')",
5959
),
6060
]

python/benchmarks/bench_xml_markup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
REPEAT = 1_000
2121
SCRIPTDIR = os.path.dirname(os.path.realpath(__file__))
22-
XMLFILE = Path(f"{SCRIPTDIR}/../tests/toy_anthology/xml/2022.acl.xml")
22+
XMLFILE = Path(f"{SCRIPTDIR}/../tests/data/anthology/xml/2022.acl.xml")
2323

2424
# An example from 2022.acl.xml
2525
tree = etree.parse(XMLFILE)
@@ -38,8 +38,8 @@ def element_tostring():
3838

3939
__benchmarks__ = [
4040
(
41-
element_deepcopy,
4241
element_tostring,
43-
"XML: deepcopy <abstract> vs. convert to string",
42+
element_deepcopy,
43+
"XML <abstract>: deepcopy instead of etree.tostring",
4444
),
4545
]

python/benchmarks/bench_xml_names.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ def bench_with_iter():
8787

8888
__benchmarks__ = [
8989
(
90-
bench_with_iter,
9190
bench_with_findtext,
92-
"XML: parse <author> via iteration vs. findtext",
91+
bench_with_iter,
92+
"XML <author>: iterate instead of searching with .findtext",
9393
),
9494
]

python/benchmarks/bench_xml_parsing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
REPEAT = 3
2121
SCRIPTDIR = os.path.dirname(os.path.realpath(__file__))
22-
XMLFILE = Path(f"{SCRIPTDIR}/../tests/toy_anthology/xml/2022.acl.xml")
22+
XMLFILE = Path(f"{SCRIPTDIR}/../tests/data/anthology/xml/2022.acl.xml")
2323

2424
# Names of XML elements that may appear multiple times, and should be accumulated as a list
2525
LIST_ELEMENTS = (
@@ -181,13 +181,13 @@ def bench_with_parse_and_clear_element():
181181

182182
__benchmarks__ = [
183183
(
184-
bench_with_parse_element,
185184
bench_with_parse_single_element,
186-
"XML: parse entire <paper> vs. parse one child per function call",
185+
bench_with_parse_element,
186+
"XML <paper>: one function call instead of one per child tag",
187187
),
188188
(
189189
bench_with_parse_element,
190190
bench_with_parse_and_clear_element,
191-
"XML: parse <paper> without vs. with clearing them afterwards",
191+
"XML <paper>: clear <paper> element after parsing",
192192
),
193193
]

python/justfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ test-only-xfail: _deps
7070
typecheck: _deps
7171
poetry run mypy acl_anthology
7272

73+
# Run benchmarks
74+
benchmark: _deps
75+
poetry run richbench --percentage benchmarks/
76+
@echo ""
77+
@echo " Note: Benchmark descriptions should be interpreted as 'Is it faster to...' or"
78+
@echo " 'What is the performance impact if we...', with the highlighted columns"
79+
@echo " showing the delta."
80+
7381
# Build the documentation
7482
docs: _deps
7583
poetry run mkdocs build

0 commit comments

Comments
 (0)