1'use strict'; 2 3const common = require('../common'); 4const util = require('util'); 5 6const bench = common.createBenchmark(main, { 7 n: [5e2], 8 len: [1e2, 1e5], 9 type: [ 10 'denseArray', 11 'sparseArray', 12 'mixedArray', 13 'denseArray_showHidden', 14 ] 15}); 16 17function main({ n, len, type }) { 18 let arr = Array(len); 19 let opts; 20 21 switch (type) { 22 case 'denseArray_showHidden': 23 opts = { showHidden: true }; 24 arr = arr.fill('denseArray'); 25 break; 26 case 'denseArray': 27 arr = arr.fill('denseArray'); 28 break; 29 case 'sparseArray': 30 break; 31 case 'mixedArray': 32 for (let i = 0; i < n; i += 2) 33 arr[i] = i; 34 break; 35 default: 36 throw new Error(`Unsupported type ${type}`); 37 } 38 bench.start(); 39 for (let i = 0; i < n; i++) { 40 util.inspect(arr, opts); 41 } 42 bench.end(n); 43} 44