-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util: improve util.inspect performance
* 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: #14492 Fixes: #14487 Reviewed-By: Alexey Orlenko <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
- Loading branch information
Showing
3 changed files
with
82 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters