diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2017-07-25 22:21:12 -0400 |
---|---|---|
committer | Refael Ackermann <refack@gmail.com> | 2017-08-13 13:52:33 -0400 |
commit | 95bbb6817532a2cdf1991f452ebbc5a5b5d5a112 (patch) | |
tree | 418eee622e467d11614b04a2a572706ba5994297 /benchmark/util | |
parent | f2b01cba7b48c2410a692fe1cb29b2e88a6c5cab (diff) | |
download | node-new-95bbb6817532a2cdf1991f452ebbc5a5b5d5a112.tar.gz |
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: 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>
Diffstat (limited to 'benchmark/util')
-rw-r--r-- | benchmark/util/inspect-array.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/benchmark/util/inspect-array.js b/benchmark/util/inspect-array.js new file mode 100644 index 0000000000..44067b8b8f --- /dev/null +++ b/benchmark/util/inspect-array.js @@ -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); +} |