benchmark: enable no-empty ESLint rule

PR-URL: https://github.com/nodejs/node/pull/41831
Refs: https://eslint.org/docs/rules/no-empty
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
Rich Trott 2022-02-02 21:28:06 -08:00 committed by Node.js GitHub Bot
parent 912c297b7a
commit 776d0b4e62
11 changed files with 62 additions and 14 deletions

View file

@ -5,5 +5,6 @@ env:
es6: true
rules:
no-empty: error
no-var: error
prefer-arrow-callback: error

View file

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

View file

@ -21,6 +21,7 @@ function main({ n, statSyncType }) {
try {
fs.statSync(arg);
} catch {
// Continue regardless of error.
}
}
}

View file

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

View file

@ -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;
@ -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() {

View file

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

View file

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

View file

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

View file

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

View file

@ -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, {

View file

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