util: faster arrayToHash
The `util.format()` is used frequently, make the method faster is better. R-URL: https://github.com/nodejs/node/pull/3964 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
1de6e4f9ab
commit
3e740caaf3
3
Makefile
3
Makefile
@ -493,6 +493,9 @@ bench-url: all
|
|||||||
bench-events: all
|
bench-events: all
|
||||||
@$(NODE) benchmark/common.js events
|
@$(NODE) benchmark/common.js events
|
||||||
|
|
||||||
|
bench-util: all
|
||||||
|
@$(NODE) benchmark/common.js util
|
||||||
|
|
||||||
bench-all: bench bench-misc bench-array bench-buffer bench-url bench-events
|
bench-all: bench bench-misc bench-array bench-buffer bench-url bench-events
|
||||||
|
|
||||||
bench: bench-net bench-http bench-fs bench-tls
|
bench: bench-net bench-http bench-fs bench-tls
|
||||||
|
15
benchmark/util/inspect.js
Normal file
15
benchmark/util/inspect.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
var util = require('util');
|
||||||
|
|
||||||
|
var common = require('../common.js');
|
||||||
|
|
||||||
|
var bench = common.createBenchmark(main, {n: [5e6]});
|
||||||
|
|
||||||
|
function main(conf) {
|
||||||
|
var n = conf.n | 0;
|
||||||
|
|
||||||
|
bench.start();
|
||||||
|
for (var i = 0; i < n; i += 1) {
|
||||||
|
var r = util.inspect({a: 'a', b: 'b', c: 'c', d: 'd'});
|
||||||
|
}
|
||||||
|
bench.end(n);
|
||||||
|
}
|
@ -163,9 +163,10 @@ function stylizeNoColor(str, styleType) {
|
|||||||
function arrayToHash(array) {
|
function arrayToHash(array) {
|
||||||
var hash = Object.create(null);
|
var hash = Object.create(null);
|
||||||
|
|
||||||
array.forEach(function(val) {
|
for (var i = 0; i < array.length; i++) {
|
||||||
|
var val = array[i];
|
||||||
hash[val] = true;
|
hash[val] = true;
|
||||||
});
|
}
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user