summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2017-08-16 21:37:44 -0300
committerRuben Bridgewater <ruben@bridgewater.de>2017-09-14 21:46:25 -0300
commit6bfc439711daf4361f7ce6d9256739e1a2c07141 (patch)
tree52c4be9a4bcf5bb46430c4a84e97fa2197f94204
parent082c43400dbfacd155d44a07e0bdd5028e0c918f (diff)
downloadandroid-node-v8-6bfc439711daf4361f7ce6d9256739e1a2c07141.tar.gz
android-node-v8-6bfc439711daf4361f7ce6d9256739e1a2c07141.tar.bz2
android-node-v8-6bfc439711daf4361f7ce6d9256739e1a2c07141.zip
benchmark: improve and add more inspect benchmarks
PR-URL: https://github.com/nodejs/node/pull/14881 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
-rw-r--r--benchmark/util/format.js2
-rw-r--r--benchmark/util/inspect-array.js18
-rw-r--r--benchmark/util/inspect-proxy.js35
-rw-r--r--benchmark/util/inspect.js92
-rw-r--r--benchmark/util/normalize-encoding.js2
5 files changed, 103 insertions, 46 deletions
diff --git a/benchmark/util/format.js b/benchmark/util/format.js
index 55ce76e1db..00b59519df 100644
--- a/benchmark/util/format.js
+++ b/benchmark/util/format.js
@@ -10,7 +10,7 @@ const types = [
'no-replace'
];
const bench = common.createBenchmark(main, {
- n: [1e6],
+ n: [2e6],
type: types
});
diff --git a/benchmark/util/inspect-array.js b/benchmark/util/inspect-array.js
index 44067b8b8f..751e2c3c2d 100644
--- a/benchmark/util/inspect-array.js
+++ b/benchmark/util/inspect-array.js
@@ -4,23 +4,27 @@ const common = require('../common');
const util = require('util');
const bench = common.createBenchmark(main, {
- n: [1e2],
+ n: [1e3],
len: [1e5],
type: [
'denseArray',
'sparseArray',
- 'mixedArray'
+ 'mixedArray',
+ 'denseArray_showHidden',
]
});
-function main(conf) {
- const { n, len, type } = conf;
+function main({ n, len, type }) {
var arr = Array(len);
- var i;
+ var i, opts;
switch (type) {
+ case 'denseArray_showHidden':
+ opts = { showHidden: true };
+ arr = arr.fill('denseArray');
+ break;
case 'denseArray':
- arr = arr.fill(0);
+ arr = arr.fill('denseArray');
break;
case 'sparseArray':
break;
@@ -33,7 +37,7 @@ function main(conf) {
}
bench.start();
for (i = 0; i < n; i++) {
- util.inspect(arr);
+ util.inspect(arr, opts);
}
bench.end(n);
}
diff --git a/benchmark/util/inspect-proxy.js b/benchmark/util/inspect-proxy.js
index c220462ce7..5427df9952 100644
--- a/benchmark/util/inspect-proxy.js
+++ b/benchmark/util/inspect-proxy.js
@@ -3,42 +3,13 @@
const util = require('util');
const common = require('../common.js');
-const bench = common.createBenchmark(main, {
- v: [1, 2],
- n: [1e6]
-});
+const bench = common.createBenchmark(main, { n: [1e6] });
-function twoDifferentProxies(n) {
- // This one should be slower because we're looking up multiple proxies.
+function main({ n }) {
const proxyA = new Proxy({}, { get: () => {} });
- const proxyB = new Proxy({}, { get: () => {} });
+ const proxyB = new Proxy(() => {}, {});
bench.start();
for (var i = 0; i < n; i += 1)
util.inspect({ a: proxyA, b: proxyB }, { showProxy: true });
bench.end(n);
}
-
-function oneProxy(n) {
- // This one should be a bit faster because of the internal caching.
- const proxy = new Proxy({}, { get: () => {} });
- bench.start();
- for (var i = 0; i < n; i += 1)
- util.inspect({ a: proxy, b: proxy }, { showProxy: true });
- bench.end(n);
-}
-
-function main(conf) {
- const n = conf.n | 0;
- const v = conf.v | 0;
-
- switch (v) {
- case 1:
- oneProxy(n);
- break;
- case 2:
- twoDifferentProxies(n);
- break;
- default:
- throw new Error('Should not get to here');
- }
-}
diff --git a/benchmark/util/inspect.js b/benchmark/util/inspect.js
index 115a3b64a7..1cf889d7ee 100644
--- a/benchmark/util/inspect.js
+++ b/benchmark/util/inspect.js
@@ -3,14 +3,96 @@ var util = require('util');
var common = require('../common.js');
-var bench = common.createBenchmark(main, { n: [5e6] });
-
-function main(conf) {
- var n = conf.n | 0;
+const opts = {
+ showHidden: { showHidden: true },
+ colors: { colors: true },
+ none: undefined
+};
+var bench = common.createBenchmark(main, {
+ n: [2e6],
+ method: [
+ 'Object',
+ 'Object_empty',
+ 'Object_deep_ln',
+ 'String',
+ 'String_complex',
+ 'String_boxed',
+ 'Date',
+ 'Set',
+ 'Error',
+ 'Array',
+ 'TypedArray',
+ 'TypedArray_extra'
+ ],
+ option: Object.keys(opts)
+});
+function benchmark(n, obj, options) {
bench.start();
for (var i = 0; i < n; i += 1) {
- util.inspect({ a: 'a', b: 'b', c: 'c', d: 'd' });
+ util.inspect(obj, options);
}
bench.end(n);
}
+
+function main({ method, n, option }) {
+ var obj;
+ const options = opts[option];
+ switch (method) {
+ case 'Object':
+ benchmark(n, { a: 'a', b: 'b', c: 'c', d: 'd' }, options);
+ break;
+ case 'Object_empty':
+ benchmark(n, {}, options);
+ break;
+ case 'Object_deep_ln':
+ if (options)
+ options.depth = Infinity;
+ obj = { first:
+ { second:
+ { third:
+ { a: 'first',
+ b: 'second',
+ c: 'third',
+ d: 'fourth',
+ e: 'fifth',
+ f: 'sixth',
+ g: 'seventh' } } } };
+ benchmark(n, obj, options || { depth: Infinity });
+ break;
+ case 'String':
+ benchmark(n, 'Simple string', options);
+ break;
+ case 'String_complex':
+ benchmark(n, 'This string\nhas to be\tescaped!', options);
+ break;
+ case 'String_boxed':
+ benchmark(n, new String('string'), options);
+ break;
+ case 'Date':
+ benchmark(n, new Date(), options);
+ break;
+ case 'Set':
+ obj = new Set([5, 3]);
+ benchmark(n, obj, options);
+ break;
+ case 'Error':
+ benchmark(n, new Error('error'), options);
+ break;
+ case 'Array':
+ benchmark(n, Array(20).fill().map((_, i) => i), options);
+ break;
+ case 'TypedArray':
+ obj = new Uint8Array(Array(50).fill().map((_, i) => i));
+ benchmark(n, obj, options);
+ break;
+ case 'TypedArray_extra':
+ obj = new Uint8Array(Array(50).fill().map((_, i) => i));
+ obj.foo = 'bar';
+ obj[Symbol('baz')] = 5;
+ benchmark(n, obj, options);
+ break;
+ default:
+ throw new Error(`Unsupported method "${method}"`);
+ }
+}
diff --git a/benchmark/util/normalize-encoding.js b/benchmark/util/normalize-encoding.js
index 8c4d034781..2cdfd54442 100644
--- a/benchmark/util/normalize-encoding.js
+++ b/benchmark/util/normalize-encoding.js
@@ -19,7 +19,7 @@ const inputs = [
const bench = common.createBenchmark(main, {
input: inputs.concat(Object.keys(groupedInputs)),
- n: [1e5]
+ n: [1e7]
}, {
flags: '--expose-internals'
});