From: Brian White Date: Sun, 15 Feb 2015 04:26:50 +0000 (-0500) Subject: benchmark: add a few querystring benchmarks X-Git-Tag: v1.3.0~16 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=35ed79932c0d5adccb80ff7e734da41691a3cd00;p=platform%2Fupstream%2Fnodejs.git benchmark: add a few querystring benchmarks PR-URL: https://github.com/iojs/io.js/pull/847 Reviewed-By: Brendan Ashworth --- diff --git a/benchmark/querystring/querystring-parse.js b/benchmark/querystring/querystring-parse.js new file mode 100644 index 0000000..3d88bed --- /dev/null +++ b/benchmark/querystring/querystring-parse.js @@ -0,0 +1,33 @@ +var common = require('../common.js'); +var querystring = require('querystring'); +var v8 = require('v8'); + +var bench = common.createBenchmark(main, { + type: ['noencode', 'encodemany', 'encodelast'], + n: [1e6], +}); + +function main(conf) { + var type = conf.type; + var n = conf.n | 0; + + var inputs = { + noencode: 'foo=bar&baz=quux&xyzzy=thud', + encodemany: '%66%6F%6F=bar&%62%61%7A=quux&xyzzy=%74h%75d', + encodelast: 'foo=bar&baz=quux&xyzzy=thu%64' + }; + var input = inputs[type]; + + // Force-optimize querystring.parse() so that the benchmark doesn't get + // disrupted by the optimizer kicking in halfway through. + for (var name in inputs) + querystring.parse(inputs[name]); + + v8.setFlagsFromString('--allow_natives_syntax'); + eval('%OptimizeFunctionOnNextCall(querystring.parse)'); + + bench.start(); + for (var i = 0; i < n; i += 1) + querystring.parse(input); + bench.end(n); +} diff --git a/benchmark/querystring/querystring-stringify.js b/benchmark/querystring/querystring-stringify.js new file mode 100644 index 0000000..d4bb95c --- /dev/null +++ b/benchmark/querystring/querystring-stringify.js @@ -0,0 +1,45 @@ +var common = require('../common.js'); +var querystring = require('querystring'); +var v8 = require('v8'); + +var bench = common.createBenchmark(main, { + type: ['noencode', 'encodemany', 'encodelast'], + n: [1e6], +}); + +function main(conf) { + var type = conf.type; + var n = conf.n | 0; + + var inputs = { + noencode: { + foo: 'bar', + baz: 'quux', + xyzzy: 'thud' + }, + encodemany: { + '\u0080\u0083\u0089': 'bar', + '\u008C\u008E\u0099': 'quux', + xyzzy: '\u00A5q\u00A3r' + }, + encodelast: { + foo: 'bar', + baz: 'quux', + xyzzy: 'thu\u00AC' + } + }; + var input = inputs[type]; + + // Force-optimize querystring.stringify() so that the benchmark doesn't get + // disrupted by the optimizer kicking in halfway through. + for (var name in inputs) + querystring.stringify(inputs[name]); + + v8.setFlagsFromString('--allow_natives_syntax'); + eval('%OptimizeFunctionOnNextCall(querystring.stringify)'); + + bench.start(); + for (var i = 0; i < n; i += 1) + querystring.stringify(input); + bench.end(n); +}