({ n, value })
| 22 | } |
| 23 | |
| 24 | function 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…