Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
bench(harper.js): add benchmarks for configuration methods
Elijah Potter340f29800166
diff --git a/packages/harper.js/src/Linter.bench.ts b/packages/harper.js/src/Linter.bench.tsnew file mode 100644index 000000000..6d11c2ba4--- /dev/null+++ b/packages/harper.js/src/Linter.bench.ts@@ -0,0 +1,31 @@+import { bench } from 'vitest';+import LocalLinter from './LocalLinter';+import WorkerLinter from './WorkerLinter';++const linters = {+ WorkerLinter: WorkerLinter,+ LocalLinter: LocalLinter+};++for (const [linterName, Linter] of Object.entries(linters)) {+ const linter = new Linter();++ // Prime caches+ linter.setup();++ const defaultConfig = await linter.getDefaultLintConfig();+ const emptyIgnoreState = await linter.exportIgnoredLints();++ bench(`${linterName} set lint configuration`, async () => {+ await linter.setLintConfig(defaultConfig);+ });++ bench(`${linterName} get lint configuration`, async () => {+ await linter.getLintConfig();+ });++ bench(`${linterName} reset ignore state`, async () => {+ await linter.clearIgnoredLints();+ await linter.importIgnoredLints(emptyIgnoreState);+ });+}diff --git a/packages/harper.js/src/LocalLinter.ts b/packages/harper.js/src/LocalLinter.tsindex 1a72abd91..45e06dbe1 100644--- a/packages/harper.js/src/LocalLinter.ts+++ b/packages/harper.js/src/LocalLinter.ts@@ -20,6 +20,9 @@ export default class LocalLinter implements Linter {async setup(): Promise<void> {await this.initialize();this.inner!.lint('', Language.Plain);++ const exported = await this.exportIgnoredLints();+ await this.importIgnoredLints(exported);}async lint(text: string, options?: LintOptions): Promise<Lint[]> {