File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 58
58
"fix" : " yarn pretty && eslint --fix ." ,
59
59
"test" : " yarn grammar && jest" ,
60
60
"test:watch" : " yarn test -- --watch" ,
61
+ "test:perf" : " yarn grammar && jest --testMatch '<rootDir>/test/perftest.ts' --coverage=false" ,
61
62
"check" : " yarn ts:check && yarn pretty:check && yarn lint && yarn test" ,
62
63
"prepare" : " yarn clean && yarn grammar && yarn fix && yarn check && yarn build" ,
63
64
"pre-commit" : " npm-run-all --parallel ts:changes lint:changes" ,
Original file line number Diff line number Diff line change
1
+ import { format } from '../src/sqlFormatter.js' ;
2
+
3
+ const BASELINE = 300 ;
4
+
5
+ describe ( 'Performance test' , ( ) => {
6
+ it ( 'uses about 300 MB of memory to format empty query' , ( ) => {
7
+ format ( '' , { language : 'sql' } ) ;
8
+
9
+ expect ( memoryUsageInMB ( ) ) . toBeLessThan ( BASELINE ) ;
10
+ } ) ;
11
+
12
+ // Issue #840
13
+ it . skip ( 'should use less than 100 MB of additional memory to format ~100 KB of SQL' , ( ) => {
14
+ // Long list of values
15
+ const values = Array ( 10000 ) . fill ( 'myid' ) ;
16
+ const sql = `SELECT ${ values . join ( ', ' ) } ` ;
17
+ expect ( sql . length ) . toBeGreaterThan ( 50000 ) ;
18
+ expect ( sql . length ) . toBeLessThan ( 100000 ) ;
19
+
20
+ format ( sql , { language : 'sql' } ) ;
21
+
22
+ expect ( memoryUsageInMB ( ) ) . toBeLessThan ( BASELINE + 100 ) ;
23
+ } ) ;
24
+ } ) ;
25
+
26
+ function memoryUsageInMB ( ) {
27
+ return Math . round ( process . memoryUsage ( ) . heapUsed / 1024 / 1024 ) ;
28
+ }
You can’t perform that action at this time.
0 commit comments