Skip to content

Commit aebd031

Browse files
committed
feat: hot start support benchmark results
1 parent 8b93313 commit aebd031

16 files changed

+411
-116
lines changed

benchmark/sqlBenchmark.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ class SqlBenchmark {
128128
*/
129129
clearATNCache() {
130130
const caches = Object.keys(require.cache);
131+
const sourcePath = path.join(__dirname, '../src');
131132
caches
132-
.filter((cache) => cache.includes('dt-sql-parser/src'))
133+
.filter((cache) => cache.includes(sourcePath))
133134
.forEach((moduleName) => {
134135
const module = require.cache[moduleName]!;
135136
// Fix Memory Leak
@@ -168,6 +169,10 @@ class SqlBenchmark {
168169
this.clearATNCache();
169170
}
170171

172+
if (this.isHot && loopTimes < 2) {
173+
throw new Error('Hot start should run at least 2 times');
174+
}
175+
171176
for (let i = 0; i < loopTimes; i++) {
172177
const parser = this.getSqlParser();
173178
if (!parser[type] || typeof parser[type] !== 'function') return;
@@ -179,14 +184,10 @@ class SqlBenchmark {
179184
costTimes.push(Math.round(costTime));
180185
}
181186

182-
if (this.isHot) {
183-
avgTime = costTimes[0];
184-
} else {
185-
const filteredData = removeOutliers(costTimes);
186-
avgTime = Math.round(
187-
filteredData.reduce((prev, curr) => prev + curr, 0) / filteredData.length
188-
);
189-
}
187+
const filteredData = removeOutliers(this.isHot ? costTimes.slice(1) : costTimes);
188+
avgTime = Math.round(
189+
filteredData.reduce((prev, curr) => prev + curr, 0) / filteredData.length
190+
);
190191

191192
const result = {
192193
name,
@@ -202,7 +203,12 @@ class SqlBenchmark {
202203
}
203204

204205
getLastResults() {
205-
const reportPath = path.join(__dirname, `./reports/${this.language}.benchmark.md`);
206+
const reportPath = path.join(
207+
__dirname,
208+
'./reports',
209+
this.isHot ? 'hot_start' : 'cold_start',
210+
`${this.language}.benchmark.md`
211+
);
206212
if (this.isRelease || !fs.existsSync(reportPath)) return null;
207213

208214
const report = fs.readFileSync(reportPath, { encoding: 'utf-8' });
@@ -265,8 +271,11 @@ class SqlBenchmark {
265271
);
266272
const currentVersion = require('../package.json').version;
267273
const parsedEnvInfo = JSON.parse(envInfo);
268-
269-
const baseDir = path.join(__dirname, this.isRelease ? '../benchmark_reports' : './reports');
274+
const baseDir = path.join(
275+
__dirname,
276+
this.isRelease ? '../benchmark_reports' : './reports',
277+
this.isHot ? 'hot_start' : 'cold_start'
278+
);
270279

271280
if (!fs.existsSync(baseDir)) {
272281
fs.mkdirSync(baseDir, { recursive: true });
@@ -293,9 +302,9 @@ class SqlBenchmark {
293302

294303
writter.writeHeader('Version', 3);
295304
writter.writeText(`\`nodejs\`: ${process.version}`);
296-
writter.writeText(`\`dt-sql-parser\`: ${currentVersion}`);
297-
writter.writeText(`\`antlr4-c3\`: ${parsedEnvInfo.npmPackages['antlr4-c3']?.installed}`);
298-
writter.writeText(`\`antlr4ng\`: ${parsedEnvInfo.npmPackages['antlr4ng']?.installed}`);
305+
writter.writeText(`\`dt-sql-parser\`: v${currentVersion}`);
306+
writter.writeText(`\`antlr4-c3\`: v${parsedEnvInfo.npmPackages['antlr4-c3']?.installed}`);
307+
writter.writeText(`\`antlr4ng\`: v${parsedEnvInfo.npmPackages['antlr4ng']?.installed}`);
299308
writter.writeLine();
300309

301310
writter.writeHeader('Running Mode', 3);

benchmark_reports/flink.benchmark.md renamed to benchmark_reports/cold_start/flink.benchmark.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
FlinkSQL
55

66
### Report Time
7-
2024/8/28 11:33:36
7+
2024/9/9 19:55:03
88

99
### Device
1010
macOS 14.4.1
@@ -13,21 +13,24 @@ macOS 14.4.1
1313

1414
### Version
1515
`nodejs`: v21.6.1
16-
`dt-sql-parser`: 4.0.2
17-
`antlr4-c3`: 3.3.7
18-
`antlr4ng`: 2.0.11
16+
`dt-sql-parser`: v4.0.2
17+
`antlr4-c3`: v3.3.7
18+
`antlr4ng`: v2.0.11
19+
20+
### Running Mode
21+
Cold Start
1922

2023
### Report
2124
| Benchmark Name | Method Name |SQL Rows|Average Time(ms)|
2225
|----------------|----------------------------|--------|----------------|
23-
|Query Collection| getAllTokens | 1015 | 225 |
24-
|Query Collection| validate | 1015 | 235 |
25-
| Insert Columns | getAllTokens | 1001 | 67 |
26-
| Insert Columns | validate | 1001 | 78 |
26+
|Query Collection| getAllTokens | 1015 | 227 |
27+
|Query Collection| validate | 1015 | 221 |
28+
| Insert Columns | getAllTokens | 1001 | 65 |
29+
| Insert Columns | validate | 1001 | 65 |
2730
| Create Table | getAllTokens | 1004 | 27 |
2831
| Create Table | validate | 1004 | 26 |
29-
| Split SQL | splitSQLByStatement | 999 | 55 |
30-
|Collect Entities| getAllEntities | 1056 | 140 |
31-
| Suggestion |getSuggestionAtCaretPosition| 1056 | 135 |
32+
| Split SQL | splitSQLByStatement | 999 | 52 |
33+
|Collect Entities| getAllEntities | 1056 | 141 |
34+
| Suggestion |getSuggestionAtCaretPosition| 1056 | 131 |
3235

3336

benchmark_reports/hive.benchmark.md renamed to benchmark_reports/cold_start/hive.benchmark.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
HiveSQL
55

66
### Report Time
7-
2024/8/28 11:33:36
7+
2024/9/9 19:55:03
88

99
### Device
1010
macOS 14.4.1
@@ -13,23 +13,26 @@ macOS 14.4.1
1313

1414
### Version
1515
`nodejs`: v21.6.1
16-
`dt-sql-parser`: 4.0.2
17-
`antlr4-c3`: 3.3.7
18-
`antlr4ng`: 2.0.11
16+
`dt-sql-parser`: v4.0.2
17+
`antlr4-c3`: v3.3.7
18+
`antlr4ng`: v2.0.11
19+
20+
### Running Mode
21+
Cold Start
1922

2023
### Report
2124
| Benchmark Name | Method Name |SQL Rows|Average Time(ms)|
2225
|----------------|----------------------------|--------|----------------|
23-
|Query Collection| getAllTokens | 1015 | 180 |
26+
|Query Collection| getAllTokens | 1015 | 185 |
2427
|Query Collection| validate | 1015 | 179 |
25-
| Update Table | getAllTokens | 1011 | 117 |
26-
| Update Table | validate | 1011 | 117 |
27-
| Insert Columns | getAllTokens | 1001 | 330 |
28-
| Insert Columns | validate | 1001 | 323 |
29-
| Create Table | getAllTokens | 1002 | 20 |
28+
| Update Table | getAllTokens | 1011 | 112 |
29+
| Update Table | validate | 1011 | 109 |
30+
| Insert Columns | getAllTokens | 1001 | 329 |
31+
| Insert Columns | validate | 1001 | 329 |
32+
| Create Table | getAllTokens | 1002 | 21 |
3033
| Create Table | validate | 1002 | 20 |
31-
| Split SQL | splitSQLByStatement | 1001 | 71 |
32-
|Collect Entities| getAllEntities | 1066 | 105 |
33-
| Suggestion |getSuggestionAtCaretPosition| 1066 | 98 |
34+
| Split SQL | splitSQLByStatement | 1001 | 72 |
35+
|Collect Entities| getAllEntities | 1066 | 106 |
36+
| Suggestion |getSuggestionAtCaretPosition| 1066 | 100 |
3437

3538

benchmark_reports/impala.benchmark.md renamed to benchmark_reports/cold_start/impala.benchmark.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
ImpalaSQL
55

66
### Report Time
7-
2024/8/28 11:33:36
7+
2024/9/9 19:55:03
88

99
### Device
1010
macOS 14.4.1
@@ -13,23 +13,26 @@ macOS 14.4.1
1313

1414
### Version
1515
`nodejs`: v21.6.1
16-
`dt-sql-parser`: 4.0.2
17-
`antlr4-c3`: 3.3.7
18-
`antlr4ng`: 2.0.11
16+
`dt-sql-parser`: v4.0.2
17+
`antlr4-c3`: v3.3.7
18+
`antlr4ng`: v2.0.11
19+
20+
### Running Mode
21+
Cold Start
1922

2023
### Report
2124
| Benchmark Name | Method Name |SQL Rows|Average Time(ms)|
2225
|----------------|----------------------------|--------|----------------|
23-
|Query Collection| getAllTokens | 1015 | 75 |
24-
|Query Collection| validate | 1015 | 74 |
25-
| Update Table | getAllTokens | 1011 | 115 |
26-
| Update Table | validate | 1011 | 116 |
27-
| Insert Columns | getAllTokens | 1001 | 213 |
28-
| Insert Columns | validate | 1001 | 215 |
26+
|Query Collection| getAllTokens | 1015 | 71 |
27+
|Query Collection| validate | 1015 | 71 |
28+
| Update Table | getAllTokens | 1011 | 113 |
29+
| Update Table | validate | 1011 | 108 |
30+
| Insert Columns | getAllTokens | 1001 | 208 |
31+
| Insert Columns | validate | 1001 | 213 |
2932
| Create Table | getAllTokens | 1002 | 23 |
3033
| Create Table | validate | 1002 | 23 |
31-
| Split SQL | splitSQLByStatement | 1001 | 68 |
32-
|Collect Entities| getAllEntities | 1066 | 81 |
33-
| Suggestion |getSuggestionAtCaretPosition| 1066 | 75 |
34+
| Split SQL | splitSQLByStatement | 1001 | 65 |
35+
|Collect Entities| getAllEntities | 1066 | 82 |
36+
| Suggestion |getSuggestionAtCaretPosition| 1066 | 83 |
3437

3538

benchmark_reports/mysql.benchmark.md renamed to benchmark_reports/cold_start/mysql.benchmark.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
MySQL
55

66
### Report Time
7-
2024/8/28 11:33:36
7+
2024/9/9 19:55:03
88

99
### Device
1010
macOS 14.4.1
@@ -13,23 +13,26 @@ macOS 14.4.1
1313

1414
### Version
1515
`nodejs`: v21.6.1
16-
`dt-sql-parser`: 4.0.2
17-
`antlr4-c3`: 3.3.7
18-
`antlr4ng`: 2.0.11
16+
`dt-sql-parser`: v4.0.2
17+
`antlr4-c3`: v3.3.7
18+
`antlr4ng`: v2.0.11
19+
20+
### Running Mode
21+
Cold Start
1922

2023
### Report
2124
| Benchmark Name | Method Name |SQL Rows|Average Time(ms)|
2225
|----------------|----------------------------|--------|----------------|
23-
|Query Collection| getAllTokens | 1015 | 1299 |
24-
|Query Collection| validate | 1015 | 1290 |
25-
| Update Table | getAllTokens | 1011 | 831 |
26-
| Update Table | validate | 1011 | 817 |
27-
| Insert Columns | getAllTokens | 1001 | 256 |
28-
| Insert Columns | validate | 1001 | 261 |
29-
| Create Table | getAllTokens | 1002 | 45 |
30-
| Create Table | validate | 1002 | 44 |
31-
| Split SQL | splitSQLByStatement | 1001 | 286 |
32-
|Collect Entities| getAllEntities | 1066 | 517 |
33-
| Suggestion |getSuggestionAtCaretPosition| 1066 | 486 |
26+
|Query Collection| getAllTokens | 1015 | 1281 |
27+
|Query Collection| validate | 1015 | 1254 |
28+
| Update Table | getAllTokens | 1011 | 876 |
29+
| Update Table | validate | 1011 | 842 |
30+
| Insert Columns | getAllTokens | 1001 | 261 |
31+
| Insert Columns | validate | 1001 | 266 |
32+
| Create Table | getAllTokens | 1002 | 48 |
33+
| Create Table | validate | 1002 | 45 |
34+
| Split SQL | splitSQLByStatement | 1001 | 287 |
35+
|Collect Entities| getAllEntities | 1066 | 474 |
36+
| Suggestion |getSuggestionAtCaretPosition| 1066 | 462 |
3437

3538

benchmark_reports/postgresql.benchmark.md renamed to benchmark_reports/cold_start/postgresql.benchmark.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
PostgreSQL
55

66
### Report Time
7-
2024/8/28 11:33:36
7+
2024/9/9 19:55:03
88

99
### Device
1010
macOS 14.4.1
@@ -13,23 +13,26 @@ macOS 14.4.1
1313

1414
### Version
1515
`nodejs`: v21.6.1
16-
`dt-sql-parser`: 4.0.2
17-
`antlr4-c3`: 3.3.7
18-
`antlr4ng`: 2.0.11
16+
`dt-sql-parser`: v4.0.2
17+
`antlr4-c3`: v3.3.7
18+
`antlr4ng`: v2.0.11
19+
20+
### Running Mode
21+
Cold Start
1922

2023
### Report
2124
| Benchmark Name | Method Name |SQL Rows|Average Time(ms)|
2225
|----------------|----------------------------|--------|----------------|
23-
|Query Collection| getAllTokens | 1015 | 1063 |
24-
|Query Collection| validate | 1015 | 1071 |
25-
| Update Table | getAllTokens | 1011 | 1216 |
26-
| Update Table | validate | 1011 | 1171 |
27-
| Insert Columns | getAllTokens | 1001 | 538 |
28-
| Insert Columns | validate | 1001 | 573 |
29-
| Create Table | getAllTokens | 1002 | 270 |
30-
| Create Table | validate | 1002 | 288 |
31-
| Split SQL | splitSQLByStatement | 1001 | 579 |
32-
|Collect Entities| getAllEntities | 1066 | 829 |
33-
| Suggestion |getSuggestionAtCaretPosition| 1066 | 810 |
26+
|Query Collection| getAllTokens | 1015 | 1086 |
27+
|Query Collection| validate | 1015 | 1078 |
28+
| Update Table | getAllTokens | 1011 | 1193 |
29+
| Update Table | validate | 1011 | 1183 |
30+
| Insert Columns | getAllTokens | 1001 | 539 |
31+
| Insert Columns | validate | 1001 | 565 |
32+
| Create Table | getAllTokens | 1002 | 294 |
33+
| Create Table | validate | 1002 | 275 |
34+
| Split SQL | splitSQLByStatement | 1001 | 597 |
35+
|Collect Entities| getAllEntities | 1066 | 797 |
36+
| Suggestion |getSuggestionAtCaretPosition| 1066 | 776 |
3437

3538

benchmark_reports/spark.benchmark.md renamed to benchmark_reports/cold_start/spark.benchmark.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
SparkSQL
55

66
### Report Time
7-
2024/8/28 11:33:36
7+
2024/9/9 19:55:03
88

99
### Device
1010
macOS 14.4.1
@@ -13,23 +13,26 @@ macOS 14.4.1
1313

1414
### Version
1515
`nodejs`: v21.6.1
16-
`dt-sql-parser`: 4.0.2
17-
`antlr4-c3`: 3.3.7
18-
`antlr4ng`: 2.0.11
16+
`dt-sql-parser`: v4.0.2
17+
`antlr4-c3`: v3.3.7
18+
`antlr4ng`: v2.0.11
19+
20+
### Running Mode
21+
Cold Start
1922

2023
### Report
2124
| Benchmark Name | Method Name |SQL Rows|Average Time(ms)|
2225
|----------------|----------------------------|--------|----------------|
23-
|Query Collection| getAllTokens | 1015 | 271 |
24-
|Query Collection| validate | 1015 | 262 |
25-
| Update Table | getAllTokens | 1011 | 226 |
26-
| Update Table | validate | 1011 | 227 |
27-
| Insert Columns | getAllTokens | 1001 | 202 |
26+
|Query Collection| getAllTokens | 1015 | 268 |
27+
|Query Collection| validate | 1015 | 259 |
28+
| Update Table | getAllTokens | 1011 | 232 |
29+
| Update Table | validate | 1011 | 226 |
30+
| Insert Columns | getAllTokens | 1001 | 198 |
2831
| Insert Columns | validate | 1001 | 200 |
2932
| Create Table | getAllTokens | 1002 | 29 |
30-
| Create Table | validate | 1002 | 29 |
33+
| Create Table | validate | 1002 | 30 |
3134
| Split SQL | splitSQLByStatement | 1001 | 111 |
32-
|Collect Entities| getAllEntities | 1066 | 173 |
33-
| Suggestion |getSuggestionAtCaretPosition| 1066 | 158 |
35+
|Collect Entities| getAllEntities | 1066 | 170 |
36+
| Suggestion |getSuggestionAtCaretPosition| 1066 | 164 |
3437

3538

0 commit comments

Comments
 (0)