Skip to content

Commit

Permalink
refactor: fix scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Nytelife26 committed Jul 16, 2024
1 parent 5d81d3d commit fca1779
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
31 changes: 15 additions & 16 deletions scripts/benchmark_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,29 @@
with file_path.open(encoding="utf-8", errors="replace") as fh:
_text = fh.read()

proselint.checks.registry.populate_enabled(_cfg["checks"])
_checks = proselint.checks.registry.get_all_enabled()
proselint.checks.registry.discover()
_checks = proselint.checks.registry.get_all_enabled(_cfg["checks"])

print("\n############# Benchmark manually optimized Checks ###################")
print("############# * or with calculations in check() ###################")

specials = [
"proselint.checks.misc.waxed.check",
"proselint.checks.terms.venery.check",
"proselint.checks.uncomparables.misc.check_1",
"proselint.checks.misc.waxed",
"proselint.checks.terms.venery",
"proselint.checks.uncomparables.misc",
]

cache.clear()
for check in _checks:
_name = f"{check.__module__}.{check.__name__}"
_name = f"{check.__module__}.{check.path}"
if _name in specials:
_dur = timeit("_e = check(_text)", globals=locals(), number=1)
_dur = timeit("_e = check.dispatch_with_flags(_text)", globals=locals(), number=1)
print(f"{_name} took {_dur * 1000:.3f} ms -> uncached")
_dur = timeit("_e = check(_text)", globals=locals(), number=1)
_dur = timeit("_e = check.dispatch_with_flags(_text)", globals=locals(), number=1)
print(f"{_name} took {_dur * 1000:.3f} ms -> cached")
_dur = timeit("_e = check(_text)", globals=locals(), number=1)
_dur = timeit("_e = check.dispatch_with_flags(_text)", globals=locals(), number=1)
print(f"{_name} took {_dur * 1000:.3f} ms -> cached")
_dur = timeit("_e = check(_text)", globals=locals(), number=1)
_dur = timeit("_e = check.dispatch_with_flags(_text)", globals=locals(), number=1)
print(f"{_name} took {_dur * 1000:.3f} ms -> cached")

# ########## output with memoize_const
Expand All @@ -80,25 +80,24 @@
print("\n############# Benchmark reimpl. of slowest check ###################")

specials = [
"proselint.checks.needless_variants.misc.check_1",
"proselint.checks.needless_variants.misc.check_2",
"proselint.checks.needless_variants.misc",
]

for check in _checks:
_name = f"{check.__module__}.{check.__name__}"
_name = f"{check.__module__}.{check.path}"
if _name in specials:
for _i in range(3):
_dur = timeit("_e = check(_text)", globals=locals(), number=1)
_dur = timeit("_e = check.dispatch_with_flags(_text)", globals=locals(), number=1)
print(f"{_name} took {_dur * 1000:.3f} ms -> run{_i}")


print("\n############# Benchmark all Checks ###################")

result = {}
for check in _checks:
_name = f"{check.__module__}.{check.__name__}"
_name = f"{check.__module__}.{check.path}"
# print(f"Will now run: {_name}")
result[_name] = timeit("_e = check(_text)", globals=locals(), number=10)
result[_name] = timeit("_e = check.dispatch_with_flags(_text)", globals=locals(), number=10)

result = dict(sorted(result.items(), key=lambda item: item[1]))
for _key, _value in result.items():
Expand Down
6 changes: 2 additions & 4 deletions scripts/benchmark_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,14 @@
"parallel": (True, True),
"parallel-cached": (True, False),
}
registry.populate_enabled(_cfg["checks"])
_num_checks = len(registry.get_all_enabled())
_num_checks = len(registry.get_all_enabled(_cfg["checks"]))

print(f"\n############# lint(demo.md) - {_os}, {_num_checks} checks")

for _name, _val in options.items():
_cfg["parallelize"] = _val[0]
for _i in range(3):
registry.populate_enabled(_cfg["checks"])
_checks = registry.get_all_enabled()
_checks = registry.get_all_enabled(_cfg["checks"])
with file_path.open() as f_handler:
_text = f_handler.read()
if _val[1]:
Expand Down

0 comments on commit fca1779

Please sign in to comment.