Updated docs with fastuaparser and new benchmarks, cleaner structure.
This commit is contained in:
+17
-19
@@ -23,13 +23,14 @@ matplotlib.rcParams["svg.fonttype"] = "path" # text as paths: renders anywhere
|
||||
import matplotlib.pyplot as plt # noqa: E402
|
||||
|
||||
# µs per cold parse, from scripts/bench.py.
|
||||
# fastuaparser (~1 µs, 1M parses/s) and cached results are too far off
|
||||
# this scale to draw meaningfully and are only mentioned in the README.
|
||||
US = {
|
||||
"user-agent-parser": 8.2,
|
||||
"uarite": 17.7,
|
||||
"ua-parser (Rust)": 46.6,
|
||||
"ua-parser (RE2)": 77.1,
|
||||
"ua-parser": 321.5,
|
||||
"user-agents": 334.4,
|
||||
"uarite": 18.0,
|
||||
"ua-parser (Rust)": 38.1,
|
||||
"ua-parser (RE2)": 71.7,
|
||||
"ua-parser": 304.7,
|
||||
"user-agents": 324.6,
|
||||
}
|
||||
|
||||
#: Readable on both white and dark backgrounds.
|
||||
@@ -41,29 +42,26 @@ values = [v for _, v in data][::-1]
|
||||
colors = ["#6e6e6e"] * len(data)
|
||||
colors[names.index("uarite")] = "#2b6cb0"
|
||||
|
||||
fig, ax = plt.subplots(figsize=(12, 1.7), dpi=100)
|
||||
fig, ax = plt.subplots(figsize=(12, 1.5), dpi=100)
|
||||
bars = ax.barh(names, values, color=colors, height=0.82)
|
||||
ax.set_xlim(0, max(values))
|
||||
xmax = max(values)
|
||||
ax.set_xlim(0, xmax)
|
||||
ax.axis("off")
|
||||
|
||||
for bar, name, v in zip(bars, names, values):
|
||||
# Round to two significant digits: 121951 -> "120 000".
|
||||
rounded = round(v, 1 - int(f"{v:.0e}".split("e")[1]))
|
||||
label = f"{name} {rounded:,.0f}".replace(",", " ")
|
||||
label = f"{rounded:,.0f} {name}".replace(",", " ")
|
||||
# va="center" centers the font bbox incl. descender space, which leaves
|
||||
# the glyphs slightly high; nudge down to optically center on the bar.
|
||||
y = bar.get_y() + bar.get_height() / 2 - 0.09
|
||||
if bar.get_width() > max(values) * 0.28:
|
||||
# Long bar: white text inside, right-aligned at the bar end.
|
||||
ax.text(bar.get_width() - max(values) * 0.012, y, label,
|
||||
va="center", ha="right", color="white", fontsize=11)
|
||||
else:
|
||||
# Short bar: theme-neutral gray text just past the bar end.
|
||||
ax.text(bar.get_width() + max(values) * 0.012, y, label,
|
||||
va="center", color=OUTSIDE, fontsize=11)
|
||||
# All labels after the bar: theme-neutral gray, number before name.
|
||||
# The longest bar's label overflows the axes; bbox_inches="tight"
|
||||
# below expands the canvas to include it, so no dead space remains.
|
||||
ax.text(bar.get_width() + xmax * 0.012, y, label,
|
||||
va="center", color=OUTSIDE, fontsize=11)
|
||||
|
||||
fig.tight_layout(pad=0.2)
|
||||
out = Path("docs/bench-speed.svg")
|
||||
out.parent.mkdir(exist_ok=True)
|
||||
fig.savefig(out, transparent=True)
|
||||
fig.savefig(out, transparent=True, bbox_inches="tight", pad_inches=0.02)
|
||||
print("wrote", out)
|
||||
|
||||
Reference in New Issue
Block a user