0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/benchmark/util/inspect-array.js
Sarah Meyer 50fe1a8409 tools, benchmark: test util benchmark
Create a minimal test for the util benchmark files.

PR-URL: https://github.com/nodejs/node/pull/16050
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
2017-10-28 13:56:44 -07:00

47 lines
934 B
JavaScript

'use strict';
const common = require('../common');
const util = require('util');
const bench = common.createBenchmark(main, {
n: [1e3],
len: [1e5],
type: [
'denseArray',
'sparseArray',
'mixedArray',
'denseArray_showHidden',
]
});
function main({ n, len, type }) {
var arr = Array(len);
var i, opts;
// For testing, if supplied with an empty type, default to denseArray.
type = type || 'denseArray';
switch (type) {
case 'denseArray_showHidden':
opts = { showHidden: true };
arr = arr.fill('denseArray');
break;
case 'denseArray':
arr = arr.fill('denseArray');
break;
case 'sparseArray':
break;
case 'mixedArray':
for (i = 0; i < n; i += 2)
arr[i] = i;
break;
default:
throw new Error(`Unsupported type ${type}`);
}
bench.start();
for (i = 0; i < n; i++) {
util.inspect(arr, opts);
}
bench.end(n);
}