Skip to content

Commit

Permalink
benchmark: enable no-empty ESLint rule
Browse files Browse the repository at this point in the history
PR-URL: #41831
Refs: https://eslint.org/docs/rules/no-empty
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
  • Loading branch information
Trott authored and ruyadorno committed Feb 8, 2022
1 parent 72f02d8 commit ad32ad6
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 14 deletions.
1 change: 1 addition & 0 deletions benchmark/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ env:
es6: true

rules:
no-empty: error
no-var: error
prefer-arrow-callback: error
2 changes: 1 addition & 1 deletion benchmark/es/foreach-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function useFor(n, items, count) {
function useForOf(n, items) {
bench.start();
for (let i = 0; i < n; i++) {
// eslint-disable-next-line no-unused-vars
// eslint-disable-next-line no-unused-vars, no-empty
for (const item of items) {}
}
bench.end(n);
Expand Down
1 change: 1 addition & 0 deletions benchmark/fs/bench-statSync-failure.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function main({ n, statSyncType }) {
try {
fs.statSync(arg);
} catch {
// Continue regardless of error.
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions benchmark/fs/read-stream-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ function main(conf) {
buf.fill('x');
}

try { fs.unlinkSync(filename); } catch {}
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
const ws = fs.createWriteStream(filename);
ws.on('close', runTest.bind(null, filesize, highWaterMark, encoding, n));
ws.on('drain', write);
Expand Down Expand Up @@ -81,7 +85,11 @@ function runTest(filesize, highWaterMark, encoding, n) {
});

rs.on('end', () => {
try { fs.unlinkSync(filename); } catch {}
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
// MB/sec
bench.end(bytes / (1024 * 1024));
});
Expand Down
12 changes: 10 additions & 2 deletions benchmark/fs/readfile-partitioned.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ const bench = common.createBenchmark(main, {
});

function main({ len, dur, concurrent }) {
try { fs.unlinkSync(filename); } catch {}
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
let data = Buffer.alloc(len, 'x');
fs.writeFileSync(filename, data);
data = null;
Expand All @@ -38,7 +42,11 @@ function main({ len, dur, concurrent }) {
const totalOps = reads + zips;
benchEnded = true;
bench.end(totalOps);
try { fs.unlinkSync(filename); } catch {}
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
}, dur * 1000);

function read() {
Expand Down
12 changes: 10 additions & 2 deletions benchmark/fs/readfile-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ const bench = common.createBenchmark(main, {
});

function main({ len, duration, concurrent }) {
try { fs.unlinkSync(filename); } catch { }
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
let data = Buffer.alloc(len, 'x');
fs.writeFileSync(filename, data);
data = null;
Expand All @@ -31,7 +35,11 @@ function main({ len, duration, concurrent }) {
setTimeout(() => {
benchEnded = true;
bench.end(writes);
try { fs.unlinkSync(filename); } catch { }
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
process.exit(0);
}, duration * 1000);

Expand Down
12 changes: 10 additions & 2 deletions benchmark/fs/readfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ const bench = common.createBenchmark(main, {
});

function main({ len, duration, concurrent }) {
try { fs.unlinkSync(filename); } catch {}
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
let data = Buffer.alloc(len, 'x');
fs.writeFileSync(filename, data);
data = null;
Expand All @@ -31,7 +35,11 @@ function main({ len, duration, concurrent }) {
setTimeout(() => {
benchEnded = true;
bench.end(reads);
try { fs.unlinkSync(filename); } catch {}
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
process.exit(0);
}, duration * 1000);

Expand Down
12 changes: 10 additions & 2 deletions benchmark/fs/write-stream-throughput.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ function main({ dur, encodingType, size }) {
throw new Error(`invalid encodingType: ${encodingType}`);
}

try { fs.unlinkSync(filename); } catch {}
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}

let started = false;
let ended = false;
Expand All @@ -48,7 +52,11 @@ function main({ dur, encodingType, size }) {
f.on('finish', () => {
ended = true;
const written = fs.statSync(filename).size / 1024;
try { fs.unlinkSync(filename); } catch {}
try {
fs.unlinkSync(filename);
} catch {
// Continue regardless of error.
}
bench.end(written / 1024);
});

Expand Down
6 changes: 5 additions & 1 deletion benchmark/fs/writefile-promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ function main({ encodingType, duration, concurrent, size }) {
benchEnded = true;
bench.end(writes);
for (let i = 0; i < filesWritten; i++) {
try { fs.unlinkSync(`${filename}-${i}`); } catch { }
try {
fs.unlinkSync(`${filename}-${i}`);
} catch {
// Continue regardless of error.
}
}
process.exit(0);
}, duration * 1000);
Expand Down
4 changes: 3 additions & 1 deletion benchmark/misc/punycode.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const common = require('../common.js');
let icu;
try {
icu = common.binding('icu');
} catch {}
} catch {
// Continue regardless of error.
}
const punycode = require('punycode');

const bench = common.createBenchmark(main, {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/net/net-c2s-cork.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function main({ dur, len, type }) {

function send() {
socket.cork();
while (socket.write(chunk, encoding)) {}
while (socket.write(chunk, encoding));
socket.uncork();
}
});
Expand Down

0 comments on commit ad32ad6

Please sign in to comment.