* Memory usage test for parsers
()
| 192 | * Memory usage test for parsers |
| 193 | */ |
| 194 | function testParserMemoryUsage () { |
| 195 | console.log("\n📊 Parser Memory Usage"); |
| 196 | console.log("-".repeat(40)); |
| 197 | |
| 198 | const jsonParser = parsers.get("application/json"); |
| 199 | const jsonlParser = parsers.get("application/jsonl"); |
| 200 | const formParser = parsers.get("application/x-www-form-urlencoded"); |
| 201 | |
| 202 | // Test with large datasets |
| 203 | const iterations = 1000; |
| 204 | |
| 205 | // JSON test |
| 206 | const jsonStart = process.memoryUsage(); |
| 207 | for (let i = 0; i < iterations; i++) { |
| 208 | jsonParser(testData.json.large); |
| 209 | } |
| 210 | const jsonEnd = process.memoryUsage(); |
| 211 | |
| 212 | // JSONL test |
| 213 | const jsonlStart = process.memoryUsage(); |
| 214 | for (let i = 0; i < iterations; i++) { |
| 215 | jsonlParser(testData.jsonl.large); |
| 216 | } |
| 217 | const jsonlEnd = process.memoryUsage(); |
| 218 | |
| 219 | // Form test |
| 220 | const formStart = process.memoryUsage(); |
| 221 | for (let i = 0; i < iterations; i++) { |
| 222 | formParser(testData.form.large); |
| 223 | } |
| 224 | const formEnd = process.memoryUsage(); |
| 225 | |
| 226 | console.log(`JSON Parser (${iterations} iterations):`); |
| 227 | const jsonDiff = jsonEnd.heapUsed - jsonStart.heapUsed; |
| 228 | console.log(` Heap Used: ${jsonDiff >= 0 ? "+" : ""}${formatFilesize(jsonDiff)}`); |
| 229 | |
| 230 | console.log(`JSONL Parser (${iterations} iterations):`); |
| 231 | const jsonlDiff = jsonlEnd.heapUsed - jsonlStart.heapUsed; |
| 232 | console.log(` Heap Used: ${jsonlDiff >= 0 ? "+" : ""}${formatFilesize(jsonlDiff)}`); |
| 233 | |
| 234 | console.log(`Form Parser (${iterations} iterations):`); |
| 235 | const formDiff = formEnd.heapUsed - formStart.heapUsed; |
| 236 | console.log(` Heap Used: ${formDiff >= 0 ? "+" : ""}${formatFilesize(formDiff)}`); |
| 237 | console.log(" Note: Negative values indicate garbage collection occurred during test"); |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Main execution function |
no test coverage detected