Skip to content

Commit 11f8024

Browse files
gengjiawendanbev
authored andcommitted
benchmark: replace deprecated and eliminate var in buffer-from.js
PR-URL: #26585 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
1 parent 4643fd7 commit 11f8024

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

benchmark/buffers/buffer-from.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,17 @@ function main({ len, n, source }) {
2626
const uint8array = new Uint8Array(len);
2727
const obj = { length: null }; // Results in a new, empty Buffer
2828

29-
var i;
30-
3129
switch (source) {
3230
case 'array':
3331
bench.start();
34-
for (i = 0; i < n * 1024; i++) {
32+
for (let i = 0; i < n * 1024; i++) {
3533
Buffer.from(array);
3634
}
3735
bench.end(n);
3836
break;
3937
case 'arraybuffer':
4038
bench.start();
41-
for (i = 0; i < n * 1024; i++) {
39+
for (let i = 0; i < n * 1024; i++) {
4240
Buffer.from(arrayBuf);
4341
}
4442
bench.end(n);
@@ -47,54 +45,54 @@ function main({ len, n, source }) {
4745
const offset = ~~(len / 4);
4846
const length = ~~(len / 2);
4947
bench.start();
50-
for (i = 0; i < n * 1024; i++) {
48+
for (let i = 0; i < n * 1024; i++) {
5149
Buffer.from(arrayBuf, offset, length);
5250
}
5351
bench.end(n);
5452
break;
5553
case 'buffer':
5654
bench.start();
57-
for (i = 0; i < n * 1024; i++) {
55+
for (let i = 0; i < n * 1024; i++) {
5856
Buffer.from(buffer);
5957
}
6058
bench.end(n);
6159
break;
6260
case 'uint8array':
6361
bench.start();
64-
for (i = 0; i < n * 1024; i++) {
62+
for (let i = 0; i < n * 1024; i++) {
6563
Buffer.from(uint8array);
6664
}
6765
bench.end(n);
6866
break;
6967
case 'string':
7068
bench.start();
71-
for (i = 0; i < n * 1024; i++) {
69+
for (let i = 0; i < n * 1024; i++) {
7270
Buffer.from(str);
7371
}
7472
bench.end(n);
7573
break;
7674
case 'string-utf8':
7775
bench.start();
78-
for (i = 0; i < n * 1024; i++) {
76+
for (let i = 0; i < n * 1024; i++) {
7977
Buffer.from(str, 'utf8');
8078
}
8179
bench.end(n);
8280
break;
8381
case 'string-base64':
8482
bench.start();
85-
for (i = 0; i < n * 1024; i++) {
83+
for (let i = 0; i < n * 1024; i++) {
8684
Buffer.from(str, 'base64');
8785
}
8886
bench.end(n);
8987
break;
9088
case 'object':
9189
bench.start();
92-
for (i = 0; i < n * 1024; i++) {
90+
for (let i = 0; i < n * 1024; i++) {
9391
Buffer.from(obj);
9492
}
9593
bench.end(n);
9694
break;
9795
default:
98-
assert.fail(null, null, 'Should not get here');
96+
assert.fail('Should not get here');
9997
}
10098
}

0 commit comments

Comments
 (0)