Skip to content

Commit

Permalink
benchmark: pre-optimize url.parse() before start
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-By: Fedor Indutny <[email protected]>
  • Loading branch information
bnoordhuis committed Dec 19, 2014
1 parent c4a308d commit 1a63b45
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions benchmark/url/url.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var common = require('../common.js');
var url = require('url');
var v8 = require('v8');

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

// Force-optimize url.parse() so that the benchmark doesn't get
// disrupted by the optimizer kicking in halfway through.
for (var name in inputs)
url.parse(inputs[name]);

v8.setFlagsFromString('--allow_natives_syntax');
eval('%OptimizeFunctionOnNextCall(url.parse)');

bench.start();
for (var i = 0; i < n; i += 1)
url.parse(input);
Expand Down

0 comments on commit 1a63b45

Please sign in to comment.