mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
95bbb68175
* improve util.inspect performance This is a huge performance improvement in case of sparse arrays when using util.inspect as the hole will simple be skipped. * use faster visibleKeys property lookup * add inspect-array benchmark PR-URL: https://github.com/nodejs/node/pull/14492 Fixes: https://github.com/nodejs/node/issues/14487 Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
40 lines
679 B
JavaScript
40 lines
679 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const util = require('util');
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
n: [1e2],
|
|
len: [1e5],
|
|
type: [
|
|
'denseArray',
|
|
'sparseArray',
|
|
'mixedArray'
|
|
]
|
|
});
|
|
|
|
function main(conf) {
|
|
const { n, len, type } = conf;
|
|
var arr = Array(len);
|
|
var i;
|
|
|
|
switch (type) {
|
|
case 'denseArray':
|
|
arr = arr.fill(0);
|
|
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);
|
|
}
|
|
bench.end(n);
|
|
}
|