summaryrefslogtreecommitdiff
path: root/benchmark/url/url-resolve.js
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2014-12-19 23:46:37 +0100
committerBen Noordhuis <info@bnoordhuis.nl>2014-12-20 21:33:52 +0100
commitaff56cd2b4fb26157ee55cc9377d5186e5625f32 (patch)
treed677cfb3ef41279bd0bea03ac49c5c6ca2496c9d /benchmark/url/url-resolve.js
parent6b2af5f0c7056fc8ab35633b45d6346ab2fdc4f5 (diff)
downloadandroid-node-v8-aff56cd2b4fb26157ee55cc9377d5186e5625f32.tar.gz
android-node-v8-aff56cd2b4fb26157ee55cc9377d5186e5625f32.tar.bz2
android-node-v8-aff56cd2b4fb26157ee55cc9377d5186e5625f32.zip
lib: micro-optimize url.resolve()
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: https://github.com/iojs/io.js/pull/184 Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
Diffstat (limited to 'benchmark/url/url-resolve.js')
-rw-r--r--benchmark/url/url-resolve.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/benchmark/url/url-resolve.js b/benchmark/url/url-resolve.js
new file mode 100644
index 0000000000..5f6c1f7600
--- /dev/null
+++ b/benchmark/url/url-resolve.js
@@ -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);
+}