Skip to content

Commit 9b9acba

Browse files
chore: move benchmark data creation to python script
1 parent 8b4149b commit 9b9acba

File tree

3 files changed

+77
-34
lines changed

3 files changed

+77
-34
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- margin for paragraphs [#200](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/200)
88
[d20d19f](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/d20d19fa54965f6eb94558c0b84fe9a942169fb4)
9+
- `on.attach` buffer callback [8b4149b](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/8b4149b122cfbf58b79a552ae89b3df2ddc39786)
910

1011
### Bug Fixes
1112

justfile

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ test:
66
just busted "tests"
77

88
bench:
9-
just gen-medium
9+
just generate
1010
just busted "benches"
1111

1212
[private]
@@ -62,36 +62,5 @@ update:
6262
cat-log:
6363
cat ~/.local/state/nvim/render-markdown.log
6464

65-
gen-medium:
66-
just gen-headings "1000" "temp/medium.md"
67-
just gen-table "50" "100" "temp/medium-table.md"
68-
69-
gen-large:
70-
just gen-headings "100000" "temp/large.md"
71-
72-
[private]
73-
gen-headings lines path:
74-
{{path_exists(path)}} || just gen-headings-content {{lines}} > {{path}}
75-
76-
[private]
77-
gen-headings-content lines:
78-
#!/usr/bin/env python
79-
for i in range({{lines}}):
80-
level = "#" * ((i % 6) + 1)
81-
print(f"{level} Title {i}\n")
82-
83-
[private]
84-
gen-table tables lines path:
85-
{{path_exists(path)}} || just gen-table-contents {{tables}} {{lines}} > {{path}}
86-
87-
[private]
88-
gen-table-contents tables lines:
89-
#!/usr/bin/env python
90-
for i in range({{tables}}):
91-
print(f"# Table {i}")
92-
print()
93-
print(f"| `Column 1` | **Column 2** | *Column 3* |")
94-
print(f"| -------------- | :--------------- | -------------: |")
95-
for j in range({{lines}}):
96-
print(f"| Row {j:<4} Col 1 | `Row {j:<4} Col 2` | Row {j:<4} Col 3 |")
97-
print()
65+
generate:
66+
python scripts/generate.py

scripts/generate.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import abc
2+
from argparse import ArgumentParser
3+
from dataclasses import dataclass
4+
from pathlib import Path
5+
from typing import override
6+
7+
8+
@dataclass(frozen=True)
9+
class Generator(abc.ABC):
10+
@abc.abstractmethod
11+
def name(self, size: str) -> str:
12+
pass
13+
14+
@abc.abstractmethod
15+
def create(self, n: int) -> list[list[str]]:
16+
pass
17+
18+
19+
@dataclass(frozen=True)
20+
class Heading(Generator):
21+
@override
22+
def name(self, size: str) -> str:
23+
return f"{size}.md"
24+
25+
@override
26+
def create(self, n: int) -> list[list[str]]:
27+
sections: list[list[str]] = []
28+
for i in range(10 * n):
29+
sections.append([f"{'#' * ((i % 6) + 1)} Title {i}"])
30+
return sections
31+
32+
33+
@dataclass(frozen=True)
34+
class Table(Generator):
35+
@override
36+
def name(self, size: str) -> str:
37+
return f"{size}-table.md"
38+
39+
@override
40+
def create(self, n: int) -> list[list[str]]:
41+
sections: list[list[str]] = []
42+
for i in range(n // 2):
43+
sections.append([f"# Table {i}"])
44+
sections.append(self.table(n))
45+
return sections
46+
47+
def table(self, n: int) -> list[str]:
48+
rows: list[str] = []
49+
rows.append(f"| `Column 1` | **Column 2** | *Column 3* |")
50+
rows.append(f"| -------------- | :--------------- | -------------: |")
51+
for i in range(n):
52+
rows.append(f"| Row {i:<4} Col 1 | `Row {i:<4} Col 2` | Row {i:<4} Col 3 |")
53+
return rows
54+
55+
56+
def main(force: bool) -> None:
57+
sizes: list[str] = ["small", "medium", "large"]
58+
generators: list[Generator] = [Heading(), Table()]
59+
for i, size in enumerate(sizes):
60+
n: int = 10 ** (i + 1)
61+
for generator in generators:
62+
path = Path("temp").joinpath(generator.name(size))
63+
if not path.exists() or force:
64+
sections = generator.create(n)
65+
content = "\n\n".join(["\n".join(section) for section in sections])
66+
path.write_text(content)
67+
68+
69+
if __name__ == "__main__":
70+
parser = ArgumentParser(description="Generate sample data for benchmarking")
71+
parser.add_argument("--force", action="store_true")
72+
args = parser.parse_args()
73+
main(args.force)

0 commit comments

Comments
 (0)