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

Function generateArgs

benchmark/napi/function_args/index.js:29–75  ·  view source on GitHub ↗
(argType)

Source from the content-addressed store, hash-verified

27 '10Numbers', '100Numbers', '1000Numbers'];
28
29const generateArgs = (argType) => {
30 let args = [];
31
32 if (argType === 'String') {
33 args.push('The quick brown fox jumps over the lazy dog');
34 } else if (argType === 'LongString') {
35 args.push(Buffer.alloc(32768, '42').toString());
36 } else if (argType === 'Number') {
37 args.push(Math.floor(314158964 * Math.random()));
38 } else if (argType === 'Object') {
39 args.push({
40 map: 'add',
41 operand: 10,
42 data: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
43 reduce: 'add',
44 });
45 } else if (argType === 'Array') {
46 const arr = [];
47 for (let i = 0; i < 50; ++i) {
48 arr.push(Math.random() * 10e9);
49 }
50 args.push(arr);
51 } else if (argType === 'Typedarray') {
52 const arr = new Uint32Array(1000);
53 for (let i = 0; i < 1000; ++i) {
54 arr[i] = Math.random() * 4294967296;
55 }
56 args.push(arr);
57 } else if (argType === '10Numbers') {
58 args.push(10);
59 for (let i = 0; i < 9; ++i) {
60 args = [...args, ...generateArgs('Number')];
61 }
62 } else if (argType === '100Numbers') {
63 args.push(100);
64 for (let i = 0; i < 99; ++i) {
65 args = [...args, ...generateArgs('Number')];
66 }
67 } else if (argType === '1000Numbers') {
68 args.push(1000);
69 for (let i = 0; i < 999; ++i) {
70 args = [...args, ...generateArgs('Number')];
71 }
72 }
73
74 return args;
75};
76
77const bench = common.createBenchmark(main, {
78 type: argsTypes,

Callers 1

mainFunction · 0.85

Calls 4

allocMethod · 0.80
randomMethod · 0.80
pushMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…