(name, serializer, iterations = 1000)
| 288 | const plainSerializer = serializers.get("text/plain"); |
| 289 | |
| 290 | function measureMemory (name, serializer, iterations = 1000) { |
| 291 | if (global.gc) { |
| 292 | global.gc(); |
| 293 | } |
| 294 | const before = process.memoryUsage().heapUsed; |
| 295 | |
| 296 | for (let i = 0; i < iterations; i++) { |
| 297 | serializer(testData.medium, null, 200); |
| 298 | } |
| 299 | |
| 300 | if (global.gc) { |
| 301 | global.gc(); |
| 302 | } |
| 303 | const after = process.memoryUsage().heapUsed; |
| 304 | const diff = after - before; |
| 305 | |
| 306 | console.log(`${name} (${iterations} iterations):`); |
| 307 | console.log(` Heap Used: ${diff >= 0 ? "+" : ""}${formatFilesize(diff)}`); |
| 308 | } |
| 309 | |
| 310 | measureMemory("Custom Serializer", customSerializer); |
| 311 | measureMemory("Plain Serializer", plainSerializer); |
no test coverage detected