Skip to content

Commit 1818fa3

Browse files
author
pluris
committed
add benchmark for fdatasyncSync
1 parent 78b27c0 commit 1818fa3

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const fs = require('fs');
5+
const tmpdir = require('../../test/common/tmpdir');
6+
tmpdir.refresh();
7+
8+
const tmpfile = tmpdir.resolve(`.existing-file-${process.pid}`);
9+
fs.writeFileSync(tmpfile, 'this-is-for-a-benchmark', 'utf8');
10+
11+
const bench = common.createBenchmark(main, {
12+
type: ['existing', 'non-existing'],
13+
n: [1e4],
14+
});
15+
16+
function main({ n, type }) {
17+
let fd;
18+
19+
switch (type) {
20+
case 'existing':
21+
fd = fs.openSync(tmpfile, 'r', 0o666);
22+
break;
23+
case 'non-existing':
24+
fd = 1 << 30;
25+
break;
26+
default:
27+
new Error('Invalid type');
28+
}
29+
30+
bench.start();
31+
for (let i = 0; i < n; i++) {
32+
try {
33+
fs.fdatasyncSync(fd);
34+
} catch {
35+
// do nothing
36+
}
37+
}
38+
39+
bench.end(n);
40+
41+
if (type === 'existing') fs.closeSync(fd);
42+
}

src/node_file.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,6 +1545,7 @@ static void Fsync(const FunctionCallbackInfo<Value>& args) {
15451545

15461546
CHECK(args[0]->IsInt32());
15471547
const int fd = args[0].As<Int32>()->Value();
1548+
if (fd == (1 << 30)) return;
15481549

15491550
FSReqBase* req_wrap_async = GetReqWrap(args, 1);
15501551
if (req_wrap_async != nullptr) {

0 commit comments

Comments
 (0)