MCPcopy Index your code
hub / github.com/nodejs/node / main

Function main

benchmark/misc/structured-clone.js:11–46  ·  view source on GitHub ↗
({ n, type })

Source from the content-addressed store, hash-verified

9});
10
11function main({ n, type }) {
12 const data = [];
13
14 switch (type) {
15 case 'string':
16 for (let i = 0; i < n; ++i) {
17 data.push(new Date().toISOString());
18 }
19 break;
20 case 'object':
21 for (let i = 0; i < n; ++i) {
22 data.push({ ...process.config });
23 }
24 break;
25 case 'arraybuffer':
26 for (let i = 0; i < n; ++i) {
27 data.push(new ArrayBuffer(10));
28 }
29 break;
30 default:
31 throw new Error('Unsupported payload type');
32 }
33
34 const run = type === 'arraybuffer' ? (i) => {
35 data[i] = structuredClone(data[i], { transfer: [ data[i] ] });
36 } : (i) => {
37 data[i] = structuredClone(data[i]);
38 };
39
40 bench.start();
41 for (let i = 0; i < n; ++i) {
42 run(i);
43 }
44 bench.end(n);
45 assert.strictEqual(data.length, n);
46}

Callers

nothing calls this directly

Calls 5

structuredCloneFunction · 0.85
runFunction · 0.50
pushMethod · 0.45
startMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…