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

Function main

benchmark/validators/validate-array.js:24–68  ·  view source on GitHub ↗
({ n, value })

Source from the content-addressed store, hash-verified

22}
23
24function main({ n, value }) {
25 const validate = getValidateFactory();
26
27 switch (value) {
28 case '[]':
29 value = [];
30 break;
31 case '[1,2,3]':
32 value = [1, 2, 3];
33 break;
34 }
35
36 // Warm up.
37 const length = 1024;
38 const array = [];
39 let errCase = false;
40
41 for (let i = 0; i < length; ++i) {
42 try {
43 array.push(validate(value));
44 } catch (e) {
45 errCase = true;
46 array.push(e);
47 }
48 }
49
50 bench.start();
51
52 for (let i = 0; i < n; ++i) {
53 const index = i % length;
54 try {
55 array[index] = validate(value);
56 } catch (e) {
57 array[index] = e;
58 }
59 }
60
61 bench.end(n);
62
63 // Verify the entries to prevent dead code elimination from making
64 // the benchmark invalid.
65 for (let i = 0; i < length; ++i) {
66 assert.strictEqual(typeof array[i], errCase ? 'object' : 'undefined');
67 }
68}

Callers

nothing calls this directly

Calls 5

getValidateFactoryFunction · 0.70
validateFunction · 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…