(snapshotBlob, fixtureScript, count)
| 15 | }); |
| 16 | |
| 17 | function buildSnapshot(snapshotBlob, fixtureScript, count) { |
| 18 | writeFileSync(fixtureScript, ` |
| 19 | 'use strict'; |
| 20 | const v8 = require('node:v8'); |
| 21 | for (let i = 0; i < ${count}; i++) { |
| 22 | v8.startupSnapshot.addDeserializeCallback(() => {}); |
| 23 | } |
| 24 | v8.startupSnapshot.setDeserializeMainFunction(() => {}); |
| 25 | `); |
| 26 | const result = spawnSync(process.execPath, [ |
| 27 | '--snapshot-blob', snapshotBlob, |
| 28 | '--build-snapshot', fixtureScript, |
| 29 | ]); |
| 30 | if (result.status !== 0) { |
| 31 | throw new Error(`Failed to build snapshot:\n${result.stderr}`); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | function main({ n, count }) { |
| 36 | const dir = mkdtempSync(path.join(tmpdir(), 'node-bench-snapshot-')); |
no test coverage detected