Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/base/test/node/uri.perf.test.ts
3296 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import assert from 'assert';
7
import { readFileSync } from 'fs';
8
import { FileAccess } from '../../common/network.js';
9
import { URI } from '../../common/uri.js';
10
import { ensureNoDisposablesAreLeakedInTestSuite } from '../common/utils.js';
11
12
suite('URI - perf', function () {
13
14
// COMMENT THIS OUT TO RUN TEST
15
if (1) {
16
return;
17
}
18
19
ensureNoDisposablesAreLeakedInTestSuite();
20
21
let manyFileUris: URI[];
22
setup(function () {
23
manyFileUris = [];
24
const data = readFileSync(FileAccess.asFileUri('vs/base/test/node/uri.perf.data.txt').fsPath).toString();
25
const lines = data.split('\n');
26
for (const line of lines) {
27
manyFileUris.push(URI.file(line));
28
}
29
});
30
31
function perfTest(name: string, callback: Function) {
32
test(name, _done => {
33
const t1 = Date.now();
34
callback();
35
const d = Date.now() - t1;
36
console.log(`${name} took ${d}ms (${(d / manyFileUris.length).toPrecision(3)} ms/uri) (${manyFileUris.length} uris)`);
37
_done();
38
});
39
}
40
41
perfTest('toString', function () {
42
for (const uri of manyFileUris) {
43
const data = uri.toString();
44
assert.ok(data);
45
}
46
});
47
48
perfTest('toString(skipEncoding)', function () {
49
for (const uri of manyFileUris) {
50
const data = uri.toString(true);
51
assert.ok(data);
52
}
53
});
54
55
perfTest('fsPath', function () {
56
for (const uri of manyFileUris) {
57
const data = uri.fsPath;
58
assert.ok(data);
59
}
60
});
61
62
perfTest('toJSON', function () {
63
for (const uri of manyFileUris) {
64
const data = uri.toJSON();
65
assert.ok(data);
66
}
67
});
68
69
});
70
71