Skip to content

Commit

Permalink
benchmark: swap var for let in buffer benchmarks
Browse files Browse the repository at this point in the history
In benchmark buffers 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 Aug 2, 2019
1 parent f2c1f36 commit bbcf9f0
Show file tree
Hide file tree
Showing 18 changed files with 25 additions and 25 deletions.
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

0 comments on commit bbcf9f0

Please sign in to comment.