Skip to content

Commit

Permalink
(perf) simple performance tests (#819)
Browse files Browse the repository at this point in the history
part of #676
  • Loading branch information
dummdidumm authored Feb 15, 2021
1 parent c3468e3 commit fe74fc9
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script lang="ts">
function aFunction(param: string) {
param += 1; // should error
const foo = subFunction();
function subFunction() {
return param ? 1 : 2;
}
}
function action(node: HTMLElement) {
aFunction(true); // should error
const foo = 'bar';
}
</script>

<div use:action>
<p>lorem ipsum</p>
<slot />
</div>

<NonExistentComponent
propA={1}
on:event={(evt) => {
const result = evt.detail ? aFunction(false) : aFunction('right');
result;
}}
>
<p>Inner Content</p>
</NonExistentComponent>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import * as path from 'path';
import { performance } from 'perf_hooks';
import ts from 'typescript';
import { Position, Range } from 'vscode-languageserver';
import { Document, DocumentManager } from '../../../src/lib/documents';
import { LSConfigManager } from '../../../src/ls-config';
import { TypeScriptPlugin } from '../../../src/plugins';
import { pathToUrl } from '../../../src/utils';

describe('TypeScript Plugin Performance Tests', () => {
function setup(filename: string) {
const docManager = new DocumentManager(() => document);
const testDir = path.join(__dirname, 'testfiles');
const filePath = path.join(testDir, filename);
const uri = pathToUrl(filePath);
const document = new Document(uri, ts.sys.readFile(filePath) || '');
const pluginManager = new LSConfigManager();
const plugin = new TypeScriptPlugin(docManager, pluginManager, [pathToUrl(testDir)]);
docManager.openDocument({ uri, text: document.getText() });
const updateDocument = (newText: string) =>
docManager.updateDocument({ uri, version: 1 }, [
{ range: Range.create(Position.create(9, 0), Position.create(9, 0)), text: newText }
]);
return { plugin, document, updateDocument };
}

it('should be fast enough', async () => {
const { document, plugin, updateDocument } = setup('performance');

const start = performance.now();
for (let i = 0; i < 1000; i++) {
await plugin.doHover(document, Position.create(1, 15));
await plugin.getDiagnostics(document);
await plugin.findReferences(document, Position.create(1, 15), {
includeDeclaration: true
});
await plugin.getDocumentSymbols(document);
await plugin.getSemanticTokens(document);
await plugin.prepareRename(document, Position.create(1, 15));
updateDocument('function asd() {}\n');
}
const end = performance.now();

console.log(`Performance test took ${end - start}ms`);
}).timeout(10000);
});

0 comments on commit fe74fc9

Please sign in to comment.