filters.perf.test.ts 2.3 KB
Newer Older
J
Johannes Rieken 已提交
1 2 3 4
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
J
Johannes Rieken 已提交
5
import * as filters from 'vs/base/common/filters';
A
Alexandru Dima 已提交
6
import { data } from 'vs/base/test/common/filters.perf.data';
J
Johannes Rieken 已提交
7

J
Johannes Rieken 已提交
8
const patterns = ['cci', 'ida', 'pos', 'CCI', 'enbled', 'callback', 'gGame', 'cons', 'zyx', 'aBc'];
J
Johannes Rieken 已提交
9

J
Johannes Rieken 已提交
10
const _enablePerf = false;
J
Johannes Rieken 已提交
11

A
Alexandru Dima 已提交
12
function perfSuite(name: string, callback: (this: Mocha.Suite) => void) {
J
Johannes Rieken 已提交
13 14 15 16 17 18 19
	if (_enablePerf) {
		suite(name, callback);
	}
}

perfSuite('Performance - fuzzyMatch', function () {

20
	console.log(`Matching ${data.length} items against ${patterns.length} patterns (${data.length * patterns.length} operations) `);
J
Johannes Rieken 已提交
21

22
	function perfTest(name: string, match: filters.FuzzyScorer) {
23
		test(name, () => {
J
Johannes Rieken 已提交
24

J
Johannes Rieken 已提交
25 26
			const t1 = Date.now();
			let count = 0;
J
Johannes Rieken 已提交
27 28 29 30 31 32 33
			for (let i = 0; i < 2; i++) {
				for (const pattern of patterns) {
					const patternLow = pattern.toLowerCase();
					for (const item of data) {
						count += 1;
						match(pattern, patternLow, 0, item, item.toLowerCase(), 0, false);
					}
J
Johannes Rieken 已提交
34 35
				}
			}
36
			const d = Date.now() - t1;
J
Johannes Rieken 已提交
37
			console.log(name, `${d}ms, ${Math.round(count / d) * 15}/15ms, ${Math.round(count / d)}/1ms`);
J
Johannes Rieken 已提交
38 39
		});
	}
J
Johannes Rieken 已提交
40

41
	perfTest('fuzzyScore', filters.fuzzyScore);
42 43
	perfTest('fuzzyScoreGraceful', filters.fuzzyScoreGraceful);
	perfTest('fuzzyScoreGracefulAggressive', filters.fuzzyScoreGracefulAggressive);
J
Johannes Rieken 已提交
44 45
});

46 47 48 49 50 51 52 53

perfSuite('Performance - IFilter', function () {

	function perfTest(name: string, match: filters.IFilter) {
		test(name, () => {

			const t1 = Date.now();
			let count = 0;
J
Johannes Rieken 已提交
54 55 56 57 58 59
			for (let i = 0; i < 2; i++) {
				for (const pattern of patterns) {
					for (const item of data) {
						count += 1;
						match(pattern, item);
					}
60 61 62
				}
			}
			const d = Date.now() - t1;
J
Johannes Rieken 已提交
63
			console.log(name, `${d}ms, ${Math.round(count / d) * 15}/15ms, ${Math.round(count / d)}/1ms`);
64 65 66 67 68 69 70 71 72
		});
	}

	perfTest('matchesFuzzy', filters.matchesFuzzy);
	perfTest('matchesFuzzy2', filters.matchesFuzzy2);
	perfTest('matchesPrefix', filters.matchesPrefix);
	perfTest('matchesContiguousSubString', filters.matchesContiguousSubString);
	perfTest('matchesCamelCase', filters.matchesCamelCase);
});