Skip to content

Commit

Permalink
benchmark: swap var for let in url benchmarks
Browse files Browse the repository at this point in the history
In benchmark url directory this changes for loops using var to let
when it applies for consistency

PR-URL: nodejs#28867
Reviewed-By: Jan Krems <jan.krems@gmail.com>
Reviewed-By: Khaidi Chu <i@2333.moe>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
RamirezAlex authored and Trott committed Jul 30, 2019
1 parent 3d56e89 commit 0d1b14a
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions benchmark/url/legacy-vs-whatwg-url-get-prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function useLegacy(data) {
// It's necessary to assign the values to an object
// to avoid loop invariant code motion.
bench.start();
for (var i = 0; i < len; i++) {
for (let i = 0; i < len; i++) {
const obj = data[i];
noDead.protocol = obj.protocol;
noDead.auth = obj.auth;
Expand Down Expand Up @@ -55,7 +55,7 @@ function useWHATWG(data) {
};
const len = data.length;
bench.start();
for (var i = 0; i < len; i++) {
for (let i = 0; i < len; i++) {
const obj = data[i];
noDead.protocol = obj.protocol;
noDead.auth = `${obj.username}:${obj.password}`;
Expand Down
6 changes: 3 additions & 3 deletions benchmark/url/legacy-vs-whatwg-url-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function useLegacy(data) {
const len = data.length;
var result = url.parse(data[0]); // Avoid dead code elimination
bench.start();
for (var i = 0; i < len; ++i) {
for (let i = 0; i < len; ++i) {
result = url.parse(data[i]);
}
bench.end(len);
Expand All @@ -26,7 +26,7 @@ function useWHATWGWithBase(data) {
const len = data.length;
var result = new URL(data[0][0], data[0][1]); // Avoid dead code elimination
bench.start();
for (var i = 0; i < len; ++i) {
for (let i = 0; i < len; ++i) {
const item = data[i];
result = new URL(item[0], item[1]);
}
Expand All @@ -38,7 +38,7 @@ function useWHATWGWithoutBase(data) {
const len = data.length;
var result = new URL(data[0]); // Avoid dead code elimination
bench.start();
for (var i = 0; i < len; ++i) {
for (let i = 0; i < len; ++i) {
result = new URL(data[i]);
}
bench.end(len);
Expand Down
4 changes: 2 additions & 2 deletions benchmark/url/legacy-vs-whatwg-url-searchparams-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const bench = common.createBenchmark(main, {
function useLegacy(n, input) {
querystring.parse(input);
bench.start();
for (var i = 0; i < n; i += 1) {
for (let i = 0; i < n; i += 1) {
querystring.parse(input);
}
bench.end(n);
Expand All @@ -22,7 +22,7 @@ function useLegacy(n, input) {
function useWHATWG(n, param) {
new URLSearchParams(param);
bench.start();
for (var i = 0; i < n; i += 1) {
for (let i = 0; i < n; i += 1) {
new URLSearchParams(param);
}
bench.end(n);
Expand Down
4 changes: 2 additions & 2 deletions benchmark/url/legacy-vs-whatwg-url-searchparams-serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function useLegacy(n, input, prop) {
const obj = querystring.parse(input);
querystring.stringify(obj);
bench.start();
for (var i = 0; i < n; i += 1) {
for (let i = 0; i < n; i += 1) {
querystring.stringify(obj);
}
bench.end(n);
Expand All @@ -24,7 +24,7 @@ function useWHATWG(n, param, prop) {
const obj = new URLSearchParams(param);
obj.toString();
bench.start();
for (var i = 0; i < n; i += 1) {
for (let i = 0; i < n; i += 1) {
obj.toString();
}
bench.end(n);
Expand Down
4 changes: 2 additions & 2 deletions benchmark/url/legacy-vs-whatwg-url-serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function useLegacy(data) {
const len = data.length;
var noDead = url.format(obj);
bench.start();
for (var i = 0; i < len; i++) {
for (let i = 0; i < len; i++) {
noDead = data[i].toString();
}
bench.end(len);
Expand All @@ -27,7 +27,7 @@ function useWHATWG(data) {
const len = data.length;
var noDead = obj.toString();
bench.start();
for (var i = 0; i < len; i++) {
for (let i = 0; i < len; i++) {
noDead = data[i].toString();
}
bench.end(len);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/url/url-format.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function main({ type, n }) {
url.format(inputs[name]);

bench.start();
for (var i = 0; i < n; i += 1)
for (let i = 0; i < n; i += 1)
url.format(input);
bench.end(n);
}
2 changes: 1 addition & 1 deletion benchmark/url/url-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function main({ type, n }) {
const input = inputs[type] || '';

bench.start();
for (var i = 0; i < n; i += 1)
for (let i = 0; i < n; i += 1)
url.parse(input);
bench.end(n);
}
2 changes: 1 addition & 1 deletion benchmark/url/url-resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function main({ n, href, path }) {
const p = paths[path];

bench.start();
for (var i = 0; i < n; i += 1)
for (let i = 0; i < n; i += 1)
url.resolve(h, p);
bench.end(n);
}
4 changes: 2 additions & 2 deletions benchmark/url/url-searchparams-iteration.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function forEach(n) {
};

bench.start();
for (var i = 0; i < n; i += 1)
for (let i = 0; i < n; i += 1)
params.forEach(cb);
bench.end(n);

Expand All @@ -32,7 +32,7 @@ function iterator(n) {
const noDead = [];

bench.start();
for (var i = 0; i < n; i += 1) {
for (let i = 0; i < n; i += 1) {
for (const pair of params) {
noDead[0] = pair[0];
noDead[1] = pair[1];
Expand Down
2 changes: 1 addition & 1 deletion benchmark/url/url-searchparams-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function main({ accessMethod, param, n }) {
throw new Error(`Unknown method ${accessMethod}`);

bench.start();
for (var i = 0; i < n; i += 1)
for (let i = 0; i < n; i += 1)
params[accessMethod](param);
bench.end(n);
}
2 changes: 1 addition & 1 deletion benchmark/url/url-searchparams-sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function main({ type, n }) {
const array = getParams(input);

bench.start();
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
params[searchParams] = array.slice();
params.sort();
}
Expand Down
2 changes: 1 addition & 1 deletion benchmark/url/usvstring.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function main({ input, n }) {
const str = inputs[input];

bench.start();
for (var i = 0; i < n; i++)
for (let i = 0; i < n; i++)
toUSVString(str);
bench.end(n);
}
2 changes: 1 addition & 1 deletion benchmark/url/whatwg-url-idna.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function main({ n, to, domain }) {
const method = to === 'ascii' ? domainToASCII : domainToUnicode;

bench.start();
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
method(value);
}
bench.end(n);
Expand Down
4 changes: 2 additions & 2 deletions benchmark/url/whatwg-url-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function setAndGet(data, prop) {
const len = data.length;
var result = data[0][prop];
bench.start();
for (var i = 0; i < len; ++i) {
for (let i = 0; i < len; ++i) {
result = data[i][prop];
data[i][prop] = result;
}
Expand All @@ -26,7 +26,7 @@ function get(data, prop) {
const len = data.length;
var result = data[0][prop];
bench.start();
for (var i = 0; i < len; ++i) {
for (let i = 0; i < len; ++i) {
result = data[i][prop]; // get
}
bench.end(len);
Expand Down

0 comments on commit 0d1b14a

Please sign in to comment.