diff options
author | Ruben Bridgewater <ruben@bridgewater.de> | 2017-07-26 05:21:12 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2017-08-13 22:43:48 +0300 |
commit | 116841056ae6dbc8d2cc4dcd1f8deb98d670e639 (patch) | |
tree | b8ab5f0ee80c1b8e4b6fd0f36fcb0491e9b2a986 /benchmark | |
parent | 1c008757474905cd1df912a5f8c1897cb02c81c9 (diff) |
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')
-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 00000000000..44067b8b8f8 --- /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); +} |