Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f441410

Browse filesBrowse files
JacksonTianMyles Borins
authored andcommitted
util: faster arrayToHash
The `util.format()` is used frequently, make the method faster is better. R-URL: #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>
1 parent 9855fab commit f441410
Copy full SHA for f441410

File tree

Expand file treeCollapse file tree

3 files changed

+21
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+21
-2
lines changed
Open diff view settings
Collapse file

‎Makefile‎

Copy file name to clipboardExpand all lines: Makefile
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,9 @@ bench-url: all
493493
bench-events: all
494494
@$(NODE) benchmark/common.js events
495495

496+
bench-util: all
497+
@$(NODE) benchmark/common.js util
498+
496499
bench-all: bench bench-misc bench-array bench-buffer bench-url bench-events
497500

498501
bench: bench-net bench-http bench-fs bench-tls
Collapse file

‎benchmark/util/inspect.js‎

Copy file name to clipboard
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
var util = require('util');
2+
3+
var common = require('../common.js');
4+
5+
var bench = common.createBenchmark(main, {n: [5e6]});
6+
7+
function main(conf) {
8+
var n = conf.n | 0;
9+
10+
bench.start();
11+
for (var i = 0; i < n; i += 1) {
12+
var r = util.inspect({a: 'a', b: 'b', c: 'c', d: 'd'});
13+
}
14+
bench.end(n);
15+
}
Collapse file

‎lib/util.js‎

Copy file name to clipboardExpand all lines: lib/util.js
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,10 @@ function stylizeNoColor(str, styleType) {
163163
function arrayToHash(array) {
164164
var hash = {};
165165

166-
array.forEach(function(val, idx) {
166+
for (var i = 0; i < array.length; i++) {
167+
var val = array[i];
167168
hash[val] = true;
168-
});
169+
}
169170

170171
return hash;
171172
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.