MCPcopy Create free account
hub / github.com/avoidwork/tenso / testParserMemory

Function testParserMemory

benchmarks/memory.js:226–276  ·  view source on GitHub ↗

* Tests parser memory usage

()

Source from the content-addressed store, hash-verified

224 * Tests parser memory usage
225 */
226async function testParserMemory () {
227 console.log("🔥 Parser Memory Test");
228 console.log("-".repeat(50));
229
230 const monitor = new MemoryMonitor();
231 const server = tenso({ silent: true, logging: { enabled: false } });
232 const parsers = server.parsers;
233
234 monitor.snapshot("Initial state");
235
236 // Test JSON parser
237 const jsonData = JSON.stringify({
238 items: Array.from({ length: 1000 }, (_, i) => ({
239 id: i,
240 name: `Item ${i}`,
241 data: { field1: `value${i}`, field2: Math.random() }
242 }))
243 });
244
245 const jsonParser = parsers.get("application/json");
246 for (let i = 0; i < 1000; i++) {
247 jsonParser(jsonData);
248 }
249
250 monitor.snapshot("After JSON parsing (1000 iterations)");
251
252 // Test JSONL parser
253 const jsonlData = Array.from({ length: 500 }, (_, i) =>
254 JSON.stringify({ id: i, name: `Item ${i}` })
255 ).join("\n");
256
257 const jsonlParser = parsers.get("application/jsonl");
258 for (let i = 0; i < 1000; i++) {
259 jsonlParser(jsonlData);
260 }
261
262 monitor.snapshot("After JSONL parsing (1000 iterations)");
263
264 // Test form parser
265 const formData = Array.from({ length: 100 }, (_, i) =>
266 `field${i}=value${i}&number${i}=${i}`
267 ).join("&");
268
269 const formParser = parsers.get("application/x-www-form-urlencoded");
270 for (let i = 0; i < 1000; i++) {
271 formParser(formData);
272 }
273
274 monitor.snapshot("After form parsing (1000 iterations)");
275 monitor.report();
276}
277
278/**
279 * Tests renderer memory usage

Callers 1

mainFunction · 0.85

Calls 6

snapshotMethod · 0.95
reportMethod · 0.95
tensoFunction · 0.90
jsonParserFunction · 0.85
formParserFunction · 0.85
logMethod · 0.80

Tested by

no test coverage detected