@@ -11,123 +11,125 @@ function analyzeMemoryUsage() {
1111
1212 // Test data
1313 const simpleData = { foo : { bar : 'baz' } } ;
14- const arrayData = { items : Array . from ( { length : 1000 } , ( _ , i ) => ( {
15- id : i ,
16- name : `item${ i } ` ,
17- price : i * 10 ,
18- tags : [ `tag${ i } ` , `category${ i % 10 } ` ]
19- } ) ) } ;
20- const nestedData = { level1 : { level2 : { level3 : { level4 : { value : 42 } } } } } ;
14+ const arrayData = {
15+ items : Array . from ( { length : 1000 } , ( _ , i ) => ( {
16+ id : i ,
17+ name : `item${ i } ` ,
18+ price : i * 10 ,
19+ tags : [ `tag${ i } ` , `category${ i % 10 } ` ] ,
20+ } ) ) ,
21+ } ;
22+ const _nestedData = { level1 : { level2 : { level3 : { level4 : { value : 42 } } } } } ;
2123
2224 function measureMemory ( name , fn , iterations = 10000 ) {
2325 // Force GC before measurement
2426 global . gc ( ) ;
2527 const startMemory = process . memoryUsage ( ) ;
26-
28+
2729 const startTime = process . hrtime . bigint ( ) ;
2830 for ( let i = 0 ; i < iterations ; i ++ ) {
2931 fn ( ) ;
3032 }
3133 const endTime = process . hrtime . bigint ( ) ;
32-
34+
3335 // Force GC after operations
3436 global . gc ( ) ;
3537 const endMemory = process . memoryUsage ( ) ;
36-
38+
3739 const memoryDelta = {
3840 heapUsed : endMemory . heapUsed - startMemory . heapUsed ,
3941 heapTotal : endMemory . heapTotal - startMemory . heapTotal ,
4042 external : endMemory . external - startMemory . external ,
41- rss : endMemory . rss - startMemory . rss
43+ rss : endMemory . rss - startMemory . rss ,
4244 } ;
43-
45+
4446 const timeMs = Number ( endTime - startTime ) / 1000000 ;
4547 const avgTimePerOp = timeMs / iterations ;
4648 const memoryPerOp = memoryDelta . heapUsed / iterations ;
47-
49+
4850 console . log ( `${ name } :` ) ;
4951 console . log ( ` Time: ${ timeMs . toFixed ( 2 ) } ms (${ avgTimePerOp . toFixed ( 4 ) } ms/op)` ) ;
5052 console . log ( ` Memory per operation: ${ memoryPerOp . toFixed ( 2 ) } bytes` ) ;
5153 console . log ( ` Total heap delta: ${ ( memoryDelta . heapUsed / 1024 / 1024 ) . toFixed ( 2 ) } MB` ) ;
5254 console . log ( ` Operations/sec: ${ ( iterations / ( timeMs / 1000 ) ) . toFixed ( 0 ) } ` ) ;
5355 console . log ( '' ) ;
54-
56+
5557 return { memoryPerOp, avgTimePerOp, opsPerSec : iterations / ( timeMs / 1000 ) } ;
5658 }
5759
5860 // Parsing memory analysis
5961 console . log ( '=== PARSING MEMORY ANALYSIS ===' ) ;
60-
62+
6163 measureMemory ( 'Simple Expression Parse' , ( ) => {
6264 jmespath . compile ( 'foo.bar' ) ;
6365 } ) ;
64-
66+
6567 measureMemory ( 'Complex Expression Parse' , ( ) => {
6668 jmespath . compile ( 'items[?price > `500`].name' ) ;
6769 } ) ;
68-
70+
6971 measureMemory ( 'Deep Nesting Parse' , ( ) => {
7072 jmespath . compile ( 'level1.level2.level3.level4.value' ) ;
7173 } ) ;
72-
74+
7375 measureMemory ( 'Function Call Parse' , ( ) => {
7476 jmespath . compile ( 'sort_by(items, &price)' ) ;
7577 } ) ;
7678
7779 // Evaluation memory analysis
7880 console . log ( '=== EVALUATION MEMORY ANALYSIS ===' ) ;
79-
81+
8082 measureMemory ( 'Simple Field Access' , ( ) => {
8183 jmespath . search ( simpleData , 'foo.bar' ) ;
8284 } ) ;
83-
85+
8486 measureMemory ( 'Array Projection' , ( ) => {
8587 jmespath . search ( arrayData , 'items[*].name' ) ;
8688 } ) ;
87-
89+
8890 measureMemory ( 'Filter Projection' , ( ) => {
8991 jmespath . search ( arrayData , 'items[?price > `500`].name' ) ;
9092 } ) ;
91-
93+
9294 measureMemory ( 'Function Call' , ( ) => {
9395 jmespath . search ( arrayData , 'length(items)' ) ;
9496 } ) ;
95-
97+
9698 measureMemory ( 'Complex Function' , ( ) => {
9799 jmespath . search ( arrayData , 'sort_by(items, &price)' ) ;
98100 } ) ;
99101
100102 // Token allocation analysis
101103 console . log ( '=== TOKEN ALLOCATION ANALYSIS ===' ) ;
102-
104+
103105 measureMemory ( 'Simple Tokenization' , ( ) => {
104106 jmespath . tokenize ( 'foo.bar' ) ;
105107 } ) ;
106-
108+
107109 measureMemory ( 'Complex Tokenization' , ( ) => {
108110 jmespath . tokenize ( 'items[?price > `500` && contains(tags, `"category1"`)].name' ) ;
109111 } ) ;
110112
111113 // Combined parse + eval analysis
112114 console . log ( '=== COMBINED PARSE + EVAL ANALYSIS ===' ) ;
113-
115+
114116 measureMemory ( 'Full Pipeline Simple' , ( ) => {
115117 jmespath . search ( simpleData , 'foo.bar' ) ;
116118 } ) ;
117-
119+
118120 measureMemory ( 'Full Pipeline Complex' , ( ) => {
119121 jmespath . search ( arrayData , 'items[?price > `500`].name' ) ;
120122 } ) ;
121123
122124 // Pre-compiled vs fresh parse comparison
123125 console . log ( '=== PRE-COMPILED VS FRESH PARSE ===' ) ;
124-
126+
125127 const compiledExpr = jmespath . compile ( 'items[?price > `500`].name' ) ;
126-
128+
127129 measureMemory ( 'Fresh Parse + Eval' , ( ) => {
128130 jmespath . search ( arrayData , 'items[?price > `500`].name' ) ;
129131 } ) ;
130-
132+
131133 measureMemory ( 'Pre-compiled Eval' , ( ) => {
132134 jmespath . TreeInterpreter . search ( compiledExpr , arrayData ) ;
133135 } ) ;
0 commit comments