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

Function testJsonSerialization

benchmarks/basic-http.js:125–171  ·  view source on GitHub ↗

* Tests JSON serialization performance

()

Source from the content-addressed store, hash-verified

123 * Tests JSON serialization performance
124 */
125function testJsonSerialization () {
126 console.log("\n📊 JSON Serialization Performance");
127 console.log("-".repeat(40));
128
129 const server = createTestServer();
130 const iterations = 50000;
131 const testData = {
132 id: 12345,
133 name: "Test Object",
134 items: Array.from({ length: 100 }, (_, i) => ({ id: i, value: `item_${i}` })),
135 metadata: {
136 created: new Date().toISOString(),
137 version: "1.0.0"
138 }
139 };
140
141 const req = {
142 method: "GET",
143 headers: { "accept": "application/json" },
144 parsed: { searchParams: new URLSearchParams() },
145 server: server
146 };
147
148 const res = {
149 statusCode: 200,
150 headers: {},
151 getHeader: name => res.headers[name],
152 removeHeader: name => delete res.headers[name],
153 header: (name, value) => res.headers[name] = value, // eslint-disable-line no-return-assign
154 getHeaders: () => res.headers
155 };
156
157 const startTime = process.hrtime.bigint();
158
159 for (let i = 0; i < iterations; i++) {
160 server.render(req, res, testData);
161 }
162
163 const endTime = process.hrtime.bigint();
164 const duration = Number(endTime - startTime) / 1e6;
165 const rps = Math.round(iterations / duration * 1000);
166
167 console.log(`Iterations: ${iterations.toLocaleString()}`);
168 console.log(`Duration: ${duration.toFixed(2)}ms`);
169 console.log(`Rate: ${rps.toLocaleString()} serializations/second`);
170 console.log(`Avg: ${(duration / iterations).toFixed(4)}ms per serialization`);
171}
172
173/**
174 * Main execution

Callers 1

mainFunction · 0.85

Calls 3

logMethod · 0.80
renderMethod · 0.80
createTestServerFunction · 0.70

Tested by

no test coverage detected