mirror of https://github.com/lukechilds/node.git
Browse Source
* 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>v6
committed by
Refael Ackermann
3 changed files with 82 additions and 19 deletions
@ -0,0 +1,39 @@ |
|||
'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); |
|||
} |
Loading…
Reference in new issue