Skip to content
Permalink
Browse files

benchmark: swap var for let in url benchmarks

In benchmark url directory this changes for loops using var to let
when it applies for consistency

PR-URL: #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 targos committed Jul 24, 2019
1 parent 9b47f77 commit 048db38ada8e9b748ecf916c5867ccb4202da628
@@ -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;
@@ -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}`;
@@ -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);
@@ -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]);
}
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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);

@@ -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];
@@ -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);
}
@@ -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();
}
@@ -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);
}
@@ -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);
@@ -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;
}
@@ -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);

0 comments on commit 048db38

Please sign in to comment.
You can’t perform that action at this time.