MCPcopy Create free account
hub / github.com/nodejs/node / buildSnapshot

Function buildSnapshot

benchmark/v8/startup-snapshot-callbacks.js:17–33  ·  view source on GitHub ↗
(snapshotBlob, fixtureScript, count)

Source from the content-addressed store, hash-verified

15});
16
17function buildSnapshot(snapshotBlob, fixtureScript, count) {
18 writeFileSync(fixtureScript, `
19'use strict';
20const v8 = require('node:v8');
21for (let i = 0; i < ${count}; i++) {
22 v8.startupSnapshot.addDeserializeCallback(() => {});
23}
24v8.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
35function main({ n, count }) {
36 const dir = mkdtempSync(path.join(tmpdir(), 'node-bench-snapshot-'));

Callers 1

mainFunction · 0.70

Calls 2

writeFileSyncFunction · 0.85
spawnSyncFunction · 0.50

Tested by

no test coverage detected