-
Notifications
You must be signed in to change notification settings - Fork 30.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace the call to Array#splice() with a faster open-coded version that creates less garbage. Add a new benchmark to prove it. With the change applied, it scores about 5% higher and that is nothing to sneeze at. PR-URL: #184 Reviewed-By: Chris Dickinson <[email protected]>
- Loading branch information
1 parent
6b2af5f
commit aff56cd
Showing
2 changed files
with
41 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
var common = require('../common.js'); | ||
var url = require('url'); | ||
var v8 = require('v8'); | ||
|
||
var bench = common.createBenchmark(main, { | ||
type: ['one'], | ||
n: [1e5], | ||
}); | ||
|
||
function main(conf) { | ||
var type = conf.type; | ||
var n = conf.n | 0; | ||
|
||
var inputs = { | ||
one: ['http://example.com/', '../../../../../etc/passwd'], | ||
}; | ||
var input = inputs[type] || []; | ||
|
||
// Force-optimize url.resolve() so that the benchmark doesn't get | ||
// disrupted by the optimizer kicking in halfway through. | ||
for (var name in inputs) | ||
url.resolve(inputs[name][0], inputs[name][1]); | ||
|
||
v8.setFlagsFromString('--allow_natives_syntax'); | ||
eval('%OptimizeFunctionOnNextCall(url.resolve)'); | ||
|
||
bench.start(); | ||
for (var i = 0; i < n; i += 1) | ||
url.resolve(input[0], input[1]); | ||
bench.end(n); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters