Skip to content
Permalink
Browse files

benchmark: swap var for let in buffer benchmarks

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 Jul 26, 2019
1 parent f2c1f36 commit bbcf9f06257ff2389b911749be6b471634142c05
@@ -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);
@@ -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);
}
@@ -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);
@@ -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);
}

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

0 comments on commit bbcf9f0

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