Skip to content

Commit 1a63b45

Browse files
committed
benchmark: pre-optimize url.parse() before start
Force V8 to optimize url.parse() before starting the actual benchmark. Tries to minimize variance between successive runs caused by the optimizer kicking in at different points. It does not seem to have much impact, CPU times are roughly the same before and afterwards; url.parse() quickly plateaus at a local optimum where most time is spent in V8 builtins, notably Runtime_StringSplit() and Object::GetElementWithReceiver() calls originating from deps/v8/src/uri.js, with no recurring optimize/deoptimize cycles that I could spot. Still, I don't see any downsides to pre-optimizing the function being benchmarked so in it goes. PR-URL: #132 Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com>
1 parent c4a308d commit 1a63b45

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

benchmark/url/url.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var common = require('../common.js');
22
var url = require('url');
3+
var v8 = require('v8');
34

45
var bench = common.createBenchmark(main, {
56
type: 'one two three four five six'.split(' '),
@@ -20,6 +21,14 @@ function main(conf) {
2021
};
2122
var input = inputs[type] || '';
2223

24+
// Force-optimize url.parse() so that the benchmark doesn't get
25+
// disrupted by the optimizer kicking in halfway through.
26+
for (var name in inputs)
27+
url.parse(inputs[name]);
28+
29+
v8.setFlagsFromString('--allow_natives_syntax');
30+
eval('%OptimizeFunctionOnNextCall(url.parse)');
31+
2332
bench.start();
2433
for (var i = 0; i < n; i += 1)
2534
url.parse(input);

0 commit comments

Comments
 (0)