Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: let refactor #28867

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-base64-decode-wrapped.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function main({ charsPerLine, linesCount, n }) {
const buffer = Buffer.alloc(bytesCount, line, 'base64');

bench.start();
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
buffer.base64Write(data, 0, bytesCount);
}
bench.end(n);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-base64-decode.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ function main({ n, size }) {
const b = Buffer.allocUnsafe(encodedSize);
b.write(s, 0, encodedSize, 'base64');
bench.start();
for (var i = 0; i < n; i += 1) b.base64Write(s, 0, s.length);
for (let i = 0; i < n; i += 1) b.base64Write(s, 0, s.length);
bench.end(n);
}
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-bytelength.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function main({ n, len, encoding }) {
}

bench.start();
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
const index = n % strings.length;
// Go!
const r = Buffer.byteLength(strings[index], encoding);
Expand Down
4 changes: 2 additions & 2 deletions benchmark/buffers/buffer-compare-offset.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ const bench = common.createBenchmark(main, {
});

function compareUsingSlice(b0, b1, len, iter) {
for (var i = 0; i < iter; i++)
for (let i = 0; i < iter; i++)
Buffer.compare(b0.slice(1, len), b1.slice(1, len));
}

function compareUsingOffset(b0, b1, len, iter) {
for (var i = 0; i < iter; i++)
for (let i = 0; i < iter; i++)
b0.compare(b1, 1, len, 1, len);
}

Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function main({ n, size }) {
b1[size - 1] = 'b'.charCodeAt(0);

bench.start();
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
Buffer.compare(b0, b1);
}
bench.end(n);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-concat.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function main({ n, pieces, pieceSize, withTotalLength }) {
const totalLength = withTotalLength ? pieces * pieceSize : undefined;

bench.start();
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
Buffer.concat(list, totalLength);
}
bench.end(n);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-indexof-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function main({ n, value }) {

let count = 0;
bench.start();
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
count += aliceBuffer.indexOf(value, 0, undefined);
}
bench.end(n);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-indexof.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function main({ n, search, encoding, type }) {
}

bench.start();
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
aliceBuffer.indexOf(search, 0, encoding);
}
bench.end(n);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-normalize-encoding.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function main({ encoding, n }) {
const { normalizeEncoding } = require('internal/util');

bench.start();
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
normalizeEncoding(encoding);
}
bench.end(n);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-read-float.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function main({ n, type, endian, value }) {
buff[`write${type}${endian}`](values[type][value], 0);

bench.start();
for (var i = 0; i !== n; i++) {
for (let i = 0; i !== n; i++) {
buff[fn](0);
}
bench.end(n);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-read-with-byteLength.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function main({ n, buf, type, byteLength }) {

buff.writeDoubleLE(0, 0);
bench.start();
for (var i = 0; i !== n; i++) {
for (let i = 0; i !== n; i++) {
buff[fn](0, byteLength);
}
bench.end(n);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function main({ n, buf, type }) {
buff.writeDoubleLE(0, 0);
bench.start();

for (var i = 0; i !== n; i++) {
for (let i = 0; i !== n; i++) {
buff[fn](0);
}
bench.end(n);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const slowBuf = new SlowBuffer(1024);
function main({ n, type }) {
const b = type === 'fast' ? buf : slowBuf;
bench.start();
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
b.slice(10, 256);
}
bench.end(n);
Expand Down
6 changes: 3 additions & 3 deletions benchmark/buffers/buffer-swap.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function swap(b, n, m) {
Buffer.prototype.htons = function htons() {
if (this.length % 2 !== 0)
throw new RangeError();
for (var i = 0; i < this.length; i += 2) {
for (let i = 0; i < this.length; i += 2) {
swap(this, i, i + 1);
}
return this;
Expand All @@ -46,7 +46,7 @@ Buffer.prototype.htonl = function htonl() {
Buffer.prototype.htonll = function htonll() {
if (this.length % 8 !== 0)
throw new RangeError();
for (var i = 0; i < this.length; i += 8) {
for (let i = 0; i < this.length; i += 8) {
swap(this, i, i + 7);
swap(this, i + 1, i + 6);
swap(this, i + 2, i + 5);
Expand All @@ -58,7 +58,7 @@ Buffer.prototype.htonll = function htonll() {
function createBuffer(len, aligned) {
len += aligned ? 0 : 1;
const buf = Buffer.allocUnsafe(len);
for (var i = 1; i <= len; i++)
for (let i = 1; i <= len; i++)
buf[i - 1] = i;
return aligned ? buf : buf.slice(1);
}
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-tojson.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function main({ n, len }) {
const buf = Buffer.allocUnsafe(len);

bench.start();
for (var i = 0; i < n; ++i)
for (let i = 0; i < n; ++i)
buf.toJSON();
bench.end(n);
}
8 changes: 4 additions & 4 deletions benchmark/buffers/buffer-write.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function main({ n, buf, type }) {
function benchBigInt(buff, fn, n) {
const m = mod[fn];
bench.start();
for (var i = 0n; i !== n; i++) {
for (let i = 0n; i !== n; i++) {
buff[fn](i & m, 0);
}
bench.end(Number(n));
Expand All @@ -98,7 +98,7 @@ function benchBigInt(buff, fn, n) {
function benchInt(buff, fn, n) {
const m = mod[fn];
bench.start();
for (var i = 0; i !== n; i++) {
for (let i = 0; i !== n; i++) {
buff[fn](i & m, 0);
}
bench.end(n);
Expand All @@ -108,15 +108,15 @@ function benchSpecialInt(buff, fn, n) {
const m = mod[fn];
const byte = byteLength[fn];
bench.start();
for (var i = 0; i !== n; i++) {
for (let i = 0; i !== n; i++) {
buff[fn](i & m, 0, byte);
}
bench.end(n);
}

function benchFloat(buff, fn, n) {
bench.start();
for (var i = 0; i !== n; i++) {
for (let i = 0; i !== n; i++) {
buff[fn](i, 0);
}
bench.end(n);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/buffers/buffer-zero.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ function main({ n, type }) {
const data = type === 'buffer' ? zeroBuffer : zeroString;

bench.start();
for (var i = 0; i < n; i++) Buffer.from(data);
for (let i = 0; i < n; i++) Buffer.from(data);
bench.end(n);
}
4 changes: 2 additions & 2 deletions benchmark/buffers/dataview-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function benchInt(dv, fn, len, le) {
const m = mod[fn];
const method = dv[fn];
bench.start();
for (var i = 0; i < len; i++) {
for (let i = 0; i < len; i++) {
method.call(dv, 0, i % m, le);
}
bench.end(len);
Expand All @@ -65,7 +65,7 @@ function benchInt(dv, fn, len, le) {
function benchFloat(dv, fn, len, le) {
const method = dv[fn];
bench.start();
for (var i = 0; i < len; i++) {
for (let i = 0; i < len; i++) {
method.call(dv, 0, i * 0.1, le);
}
bench.end(len);
Expand Down
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
Loading