Skip to content

Commit 351ee64

Browse files
dnlupMylesBorins
authored andcommitted
benchmark: use let instead of var in assert
PR-URL: #30450 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
1 parent ec49ea7 commit 351ee64

9 files changed

Lines changed: 58 additions & 47 deletions

‎benchmark/assert/deepequal-buffer.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function main({ len, n, method, strict }) {
2727
constvalue2=method.includes('not') ? expectedWrong : expected;
2828

2929
bench.start();
30-
for(vari=0;i<n;++i){
30+
for(leti=0;i<n;++i){
3131
fn(actual,value2);
3232
}
3333
bench.end(n);

‎benchmark/assert/deepequal-map.js‎

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,49 +24,58 @@ function benchmark(method, n, values, values2) {
2424
constdeepCopy=JSON.parse(JSON.stringify(values2 ? values2 : values));
2525
constexpected=newMap(deepCopy);
2626
bench.start();
27-
for(vari=0;i<n;++i){
27+
for(leti=0;i<n;++i){
2828
method(actual,expected);
2929
}
3030
bench.end(n);
3131
}
3232

3333
functionmain({ n, len, method, strict }){
3434
constarray=Array(len).fill(1);
35-
varvalues,values2;
3635

3736
switch(method){
3837
case'':
3938
// Empty string falls through to next line as default, mostly for tests.
40-
case'deepEqual_primitiveOnly':
41-
values=array.map((_,i)=>[`str_${i}`,123]);
39+
case'deepEqual_primitiveOnly':{
40+
constvalues=array.map((_,i)=>[`str_${i}`,123]);
4241
benchmark(strict ? deepStrictEqual : deepEqual,n,values);
4342
break;
44-
case'deepEqual_objectOnly':
45-
values=array.map((_,i)=>[[`str_${i}`,1],123]);
43+
}
44+
case'deepEqual_objectOnly': {
45+
constvalues=array.map((_,i)=>[[`str_${i}`,1],123]);
4646
benchmark(strict ? deepStrictEqual : deepEqual,n,values);
4747
break;
48-
case'deepEqual_mixed':
49-
values=array.map((_,i)=>[i%2 ? [`str_${i}`,1] : `str_${i}`,123]);
48+
}
49+
case'deepEqual_mixed': {
50+
constvalues=array.map(
51+
(_,i)=>[i%2 ? [`str_${i}`,1] : `str_${i}`,123]
52+
);
5053
benchmark(strict ? deepStrictEqual : deepEqual,n,values);
5154
break;
52-
case'notDeepEqual_primitiveOnly':
53-
values=array.map((_,i)=>[`str_${i}`,123]);
54-
values2=values.slice(0);
55+
}
56+
case'notDeepEqual_primitiveOnly': {
57+
constvalues=array.map((_,i)=>[`str_${i}`,123]);
58+
constvalues2=values.slice(0);
5559
values2[Math.floor(len/2)]=['w00t',123];
5660
benchmark(strict ? notDeepStrictEqual : notDeepEqual,n,values,values2);
5761
break;
58-
case'notDeepEqual_objectOnly':
59-
values=array.map((_,i)=>[[`str_${i}`,1],123]);
60-
values2=values.slice(0);
62+
}
63+
case'notDeepEqual_objectOnly': {
64+
constvalues=array.map((_,i)=>[[`str_${i}`,1],123]);
65+
constvalues2=values.slice(0);
6166
values2[Math.floor(len/2)]=[['w00t'],123];
6267
benchmark(strict ? notDeepStrictEqual : notDeepEqual,n,values,values2);
6368
break;
64-
case'notDeepEqual_mixed':
65-
values=array.map((_,i)=>[i%2 ? [`str_${i}`,1] : `str_${i}`,123]);
66-
values2=values.slice(0);
69+
}
70+
case'notDeepEqual_mixed': {
71+
constvalues=array.map(
72+
(_,i)=>[i%2 ? [`str_${i}`,1] : `str_${i}`,123]
73+
);
74+
constvalues2=values.slice(0);
6775
values2[0]=['w00t',123];
6876
benchmark(strict ? notDeepStrictEqual : notDeepEqual,n,values,values2);
6977
break;
78+
}
7079
default:
7180
thrownewError(`Unsupported method ${method}`);
7281
}

‎benchmark/assert/deepequal-object.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function main({ size, n, method, strict }) {
4242
constvalue2=method.includes('not') ? expectedWrong : expected;
4343

4444
bench.start();
45-
for(vari=0;i<n;++i){
45+
for(leti=0;i<n;++i){
4646
fn(actual,value2);
4747
}
4848
bench.end(n);

‎benchmark/assert/deepequal-prims-and-objs-big-array-set.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const bench = common.createBenchmark(main, {
2626

2727
functionrun(fn,n,actual,expected){
2828
bench.start();
29-
for(vari=0;i<n;++i){
29+
for(leti=0;i<n;++i){
3030
fn(actual,expected);
3131
}
3232
bench.end(n);
@@ -38,7 +38,7 @@ function main({ n, len, primitive, method, strict }) {
3838
constexpected=[];
3939
constexpectedWrong=[];
4040

41-
for(varx=0;x<len;x++){
41+
for(letx=0;x<len;x++){
4242
actual.push(prim);
4343
expected.push(prim);
4444
expectedWrong.push(prim);

‎benchmark/assert/deepequal-prims-and-objs-big-loop.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function main({ n, primitive, method, strict }) {
3131
constvalue2=method.includes('not') ? expectedWrong : expected;
3232

3333
bench.start();
34-
for(vari=0;i<n;++i){
34+
for(leti=0;i<n;++i){
3535
fn([actual],[value2]);
3636
}
3737
bench.end(n);

‎benchmark/assert/deepequal-set.js‎

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function benchmark(method, n, values, values2) {
2424
constdeepCopy=JSON.parse(JSON.stringify(values2 ? values2 : values));
2525
constexpected=newSet(deepCopy);
2626
bench.start();
27-
for(vari=0;i<n;++i){
27+
for(leti=0;i<n;++i){
2828
method(actual,expected);
2929
}
3030
bench.end(n);
@@ -33,45 +33,49 @@ function benchmark(method, n, values, values2) {
3333
functionmain({ n, len, method, strict }){
3434
constarray=Array(len).fill(1);
3535

36-
varvalues,values2;
37-
3836
switch(method){
3937
case'':
4038
// Empty string falls through to next line as default, mostly for tests.
41-
case'deepEqual_primitiveOnly':
42-
values=array.map((_,i)=>`str_${i}`);
39+
case'deepEqual_primitiveOnly':{
40+
constvalues=array.map((_,i)=>`str_${i}`);
4341
benchmark(strict ? deepStrictEqual : deepEqual,n,values);
4442
break;
45-
case'deepEqual_objectOnly':
46-
values=array.map((_,i)=>[`str_${i}`,null]);
43+
}
44+
case'deepEqual_objectOnly': {
45+
constvalues=array.map((_,i)=>[`str_${i}`,null]);
4746
benchmark(strict ? deepStrictEqual : deepEqual,n,values);
4847
break;
49-
case'deepEqual_mixed':
50-
values=array.map((_,i)=>{
48+
}
49+
case'deepEqual_mixed': {
50+
constvalues=array.map((_,i)=>{
5151
returni%2 ? [`str_${i}`,null] : `str_${i}`;
5252
});
5353
benchmark(strict ? deepStrictEqual : deepEqual,n,values);
5454
break;
55-
case'notDeepEqual_primitiveOnly':
56-
values=array.map((_,i)=>`str_${i}`);
57-
values2=values.slice(0);
55+
}
56+
case'notDeepEqual_primitiveOnly': {
57+
constvalues=array.map((_,i)=>`str_${i}`);
58+
constvalues2=values.slice(0);
5859
values2[Math.floor(len/2)]='w00t';
5960
benchmark(strict ? notDeepStrictEqual : notDeepEqual,n,values,values2);
6061
break;
61-
case'notDeepEqual_objectOnly':
62-
values=array.map((_,i)=>[`str_${i}`,null]);
63-
values2=values.slice(0);
62+
}
63+
case'notDeepEqual_objectOnly': {
64+
constvalues=array.map((_,i)=>[`str_${i}`,null]);
65+
constvalues2=values.slice(0);
6466
values2[Math.floor(len/2)]=['w00t'];
6567
benchmark(strict ? notDeepStrictEqual : notDeepEqual,n,values,values2);
6668
break;
67-
case'notDeepEqual_mixed':
68-
values=array.map((_,i)=>{
69+
}
70+
case'notDeepEqual_mixed': {
71+
constvalues=array.map((_,i)=>{
6972
returni%2 ? [`str_${i}`,null] : `str_${i}`;
7073
});
71-
values2=values.slice();
74+
constvalues2=values.slice();
7275
values2[0]='w00t';
7376
benchmark(strict ? notDeepStrictEqual : notDeepEqual,n,values,values2);
7477
break;
78+
}
7579
default:
7680
thrownewError(`Unsupported method "${method}"`);
7781
}

‎benchmark/assert/deepequal-typedarrays.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function main({ type, n, len, method, strict }) {
3636
constvalue2=method.includes('not') ? expectedWrong : expected;
3737

3838
bench.start();
39-
for(vari=0;i<n;++i){
39+
for(leti=0;i<n;++i){
4040
actual[0]=i;
4141
value2[0]=i;
4242
fn(actual,value2);

‎benchmark/assert/ok.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ const assert = require('assert');
66
constbench=common.createBenchmark(main,{n: [1e5]});
77

88
functionmain({ n }){
9-
vari;
109
bench.start();
11-
for(i=0;i<n;++i){
10+
for(leti=0;i<n;++i){
1211
if(i%2===0)
1312
assert(true);
1413
else

‎benchmark/assert/throws.js‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,27 @@ function main({ n, method }) {
1313
constdoNotThrowError=()=>{return'foobar';};
1414
constregExp=/foobar/;
1515
constmessage='failure';
16-
vari;
1716

1817
switch(method){
1918
case'':
2019
// Empty string falls through to next line as default, mostly for tests.
2120
case'doesNotThrow':
2221
bench.start();
23-
for(i=0;i<n;++i){
22+
for(leti=0;i<n;++i){
2423
doesNotThrow(doNotThrowError);
2524
}
2625
bench.end(n);
2726
break;
2827
case'throws_TypeError':
2928
bench.start();
30-
for(i=0;i<n;++i){
29+
for(leti=0;i<n;++i){
3130
throws(throwError,TypeError,message);
3231
}
3332
bench.end(n);
3433
break;
3534
case'throws_RegExp':
3635
bench.start();
37-
for(i=0;i<n;++i){
36+
for(leti=0;i<n;++i){
3837
throws(throwError,regExp,message);
3938
}
4039
bench.end(n);

0 commit comments

Comments
 (0)