@@ -9,10 +9,17 @@ import assert from "assert";
99import * as vscode from "vscode" ;
1010import { endToEndTestSetup } from "../endToEndTestSetup" ;
1111
12- const testData = generateTestData ( ) ;
13- const numLines = testData . split ( "\n" ) . length ;
12+ const testData = generateTestData ( 100 ) ;
13+ const shortTestData = generateTestData ( 30 ) ;
1414
15- suite ( `Performance: ${ numLines } lines JSON` , async function ( ) {
15+ const textBasedConfig : TestConfig = { thresholdMs : 100 , testData } ;
16+ const parseTreeConfig : TestConfig = { thresholdMs : 500 , testData } ;
17+ const surroundingPairConfig : TestConfig = {
18+ thresholdMs : 500 ,
19+ testData : shortTestData ,
20+ } ;
21+
22+ suite ( "Performance" , async function ( ) {
1623 endToEndTestSetup ( this ) ;
1724
1825 let previousTitle = "" ;
@@ -25,40 +32,36 @@ suite(`Performance: ${numLines} lines JSON`, async function () {
2532 }
2633 } ) ;
2734
28- const textBasedThresholdMs = 100 ;
29- const parseTreeThresholdMs = 500 ;
30- const surroundingPairThresholdMs = 30000 ;
31-
3235 test (
3336 "Remove token" ,
34- asyncSafety ( ( ) => removeToken ( textBasedThresholdMs ) ) ,
37+ asyncSafety ( ( ) => removeToken ( textBasedConfig ) ) ,
3538 ) ;
3639
37- const fixtures : [ SimpleScopeTypeType | ScopeType , number ] [ ] = [
40+ const fixtures : [ SimpleScopeTypeType | ScopeType , TestConfig ] [ ] = [
3841 // Text based
39- [ "character" , textBasedThresholdMs ] ,
40- [ "word" , textBasedThresholdMs ] ,
41- [ "token" , textBasedThresholdMs ] ,
42- [ "identifier" , textBasedThresholdMs ] ,
43- [ "line" , textBasedThresholdMs ] ,
44- [ "sentence" , textBasedThresholdMs ] ,
45- [ "paragraph" , textBasedThresholdMs ] ,
46- [ "document" , textBasedThresholdMs ] ,
47- [ "nonWhitespaceSequence" , textBasedThresholdMs ] ,
42+ [ "character" , textBasedConfig ] ,
43+ [ "word" , textBasedConfig ] ,
44+ [ "token" , textBasedConfig ] ,
45+ [ "identifier" , textBasedConfig ] ,
46+ [ "line" , textBasedConfig ] ,
47+ [ "sentence" , textBasedConfig ] ,
48+ [ "paragraph" , textBasedConfig ] ,
49+ [ "document" , textBasedConfig ] ,
50+ [ "nonWhitespaceSequence" , textBasedConfig ] ,
4851 // Parse tree based
49- [ "string" , parseTreeThresholdMs ] ,
50- [ "map" , parseTreeThresholdMs ] ,
51- [ "collectionKey" , parseTreeThresholdMs ] ,
52- [ "value" , parseTreeThresholdMs ] ,
52+ [ "string" , parseTreeConfig ] ,
53+ [ "map" , parseTreeConfig ] ,
54+ [ "collectionKey" , parseTreeConfig ] ,
55+ [ "value" , parseTreeConfig ] ,
5356 // Text based, but utilizes surrounding pair
54- [ "boundedParagraph" , surroundingPairThresholdMs ] ,
55- [ "boundedNonWhitespaceSequence" , surroundingPairThresholdMs ] ,
56- [ "collectionItem" , surroundingPairThresholdMs ] ,
57+ [ "boundedParagraph" , surroundingPairConfig ] ,
58+ [ "boundedNonWhitespaceSequence" , surroundingPairConfig ] ,
59+ [ "collectionItem" , surroundingPairConfig ] ,
5760 // Surrounding pair
58- [ { type : "surroundingPair" , delimiter : "any" } , surroundingPairThresholdMs ] ,
61+ [ { type : "surroundingPair" , delimiter : "any" } , surroundingPairConfig ] ,
5962 [
6063 { type : "surroundingPair" , delimiter : "curlyBrackets" } ,
61- surroundingPairThresholdMs ,
64+ surroundingPairConfig ,
6265 ] ,
6366 ] ;
6467
@@ -71,8 +74,8 @@ suite(`Performance: ${numLines} lines JSON`, async function () {
7174 }
7275} ) ;
7376
74- async function removeToken ( threshold : number ) {
75- await testPerformance ( threshold , {
77+ async function removeToken ( config : TestConfig ) {
78+ await testPerformance ( config , {
7679 name : "remove" ,
7780 target : {
7881 type : "primitive" ,
@@ -81,8 +84,8 @@ async function removeToken(threshold: number) {
8184 } ) ;
8285}
8386
84- async function selectScopeType ( scopeType : ScopeType , threshold : number ) {
85- await testPerformance ( threshold , {
87+ async function selectScopeType ( scopeType : ScopeType , config : TestConfig ) {
88+ await testPerformance ( config , {
8689 name : "setSelection" ,
8790 target : {
8891 type : "primitive" ,
@@ -91,7 +94,8 @@ async function selectScopeType(scopeType: ScopeType, threshold: number) {
9194 } ) ;
9295}
9396
94- async function testPerformance ( threshold : number , action : ActionDescriptor ) {
97+ async function testPerformance ( config : TestConfig , action : ActionDescriptor ) {
98+ const { testData, thresholdMs } = config ;
9599 const editor = await openNewEditor ( testData , { languageId : "json" } ) ;
96100 const position = new vscode . Position ( editor . document . lineCount - 3 , 5 ) ;
97101 const selection = new vscode . Selection ( position , position ) ;
@@ -111,8 +115,8 @@ async function testPerformance(threshold: number, action: ActionDescriptor) {
111115 console . log ( ` ${ duration } ms` ) ;
112116
113117 assert . ok (
114- duration < threshold ,
115- `Duration ${ duration } ms exceeds threshold ${ threshold } ms` ,
118+ duration < thresholdMs ,
119+ `Duration ${ duration } ms exceeds threshold ${ thresholdMs } ms` ,
116120 ) ;
117121}
118122
@@ -130,19 +134,24 @@ function getScopeTypeAndTitle(
130134}
131135
132136/**
133- * Generate a large JSON object with 100 keys, each with 100 values.
137+ * Generate a large JSON object with n- keys, each with n- values.
134138 * {
135- * "0": { "0": "value", ..., "99 ": "value" },
139+ * "0": { "0": "value", ..., "n-1 ": "value" },
136140 * ...
137- * * "99 ": { "0": "value", ..., "99 ": "value" },
141+ * "n-1 ": { "0": "value", ..., "n-1 ": "value" }
138142 * }
139143 */
140- function generateTestData ( ) : string {
144+ function generateTestData ( n : number ) : string {
141145 const value = Object . fromEntries (
142- new Array ( 100 ) . fill ( "" ) . map ( ( _ , i ) => [ i . toString ( ) , "value" ] ) ,
146+ new Array ( n ) . fill ( "" ) . map ( ( _ , i ) => [ i . toString ( ) , "value" ] ) ,
143147 ) ;
144148 const obj = Object . fromEntries (
145- new Array ( 100 ) . fill ( "" ) . map ( ( _ , i ) => [ i . toString ( ) , value ] ) ,
149+ new Array ( n ) . fill ( "" ) . map ( ( _ , i ) => [ i . toString ( ) , value ] ) ,
146150 ) ;
147151 return JSON . stringify ( obj , null , 2 ) ;
148152}
153+
154+ interface TestConfig {
155+ thresholdMs : number ;
156+ testData : string ;
157+ }
0 commit comments