Skip to content

Commit c25716b

Browse files
Uzlopaktargos
authored andcommitted
os: cache homedir, remove getCheckedFunction
PR-URL: #50037 Reviewed-By: Yagiz Nizipli <[email protected]>
1 parent e60b3ab commit c25716b

File tree

4 files changed

+95
-2
lines changed

4 files changed

+95
-2
lines changed

benchmark/os/homedir.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
const homedir = require('os').homedir;
5+
const assert = require('assert');
6+
7+
const bench = common.createBenchmark(main, {
8+
n: [1e6],
9+
});
10+
11+
function main({ n }) {
12+
// Warm up.
13+
const length = 1024;
14+
const array = [];
15+
for (let i = 0; i < length; ++i) {
16+
array.push(homedir());
17+
}
18+
19+
bench.start();
20+
for (let i = 0; i < n; ++i) {
21+
const index = i % length;
22+
array[index] = homedir();
23+
}
24+
bench.end(n);
25+
26+
// Verify the entries to prevent dead code elimination from making
27+
// the benchmark invalid.
28+
for (let i = 0; i < length; ++i) {
29+
assert.strictEqual(typeof array[i], 'string');
30+
}
31+
}

benchmark/os/hostname.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
const hostname = require('os').hostname;
5+
const assert = require('assert');
6+
7+
const bench = common.createBenchmark(main, {
8+
n: [1e6],
9+
});
10+
11+
function main({ n }) {
12+
// Warm up.
13+
const length = 1024;
14+
const array = [];
15+
for (let i = 0; i < length; ++i) {
16+
array.push(hostname());
17+
}
18+
19+
bench.start();
20+
for (let i = 0; i < n; ++i) {
21+
const index = i % length;
22+
array[index] = hostname();
23+
}
24+
bench.end(n);
25+
26+
// Verify the entries to prevent dead code elimination from making
27+
// the benchmark invalid.
28+
for (let i = 0; i < length; ++i) {
29+
assert.strictEqual(typeof array[i], 'string');
30+
}
31+
}

benchmark/os/uptime.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
'use strict';
2+
3+
const common = require('../common.js');
4+
const uptime = require('os').uptime;
5+
const assert = require('assert');
6+
7+
const bench = common.createBenchmark(main, {
8+
n: [1e5],
9+
});
10+
11+
function main({ n }) {
12+
// Warm up.
13+
const length = 1024;
14+
const array = [];
15+
for (let i = 0; i < length; ++i) {
16+
array.push(uptime());
17+
}
18+
19+
bench.start();
20+
for (let i = 0; i < n; ++i) {
21+
const index = i % length;
22+
array[index] = uptime();
23+
}
24+
bench.end(n);
25+
26+
// Verify the entries to prevent dead code elimination from making
27+
// the benchmark invalid.
28+
for (let i = 0; i < length; ++i) {
29+
assert.strictEqual(typeof array[i], 'number');
30+
}
31+
}

lib/os.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ const {
6161
} = internalBinding('os');
6262

6363
function getCheckedFunction(fn) {
64-
return hideStackFrames(function checkError(...args) {
64+
return hideStackFrames(function checkError() {
6565
const ctx = {};
66-
const ret = fn(...args, ctx);
66+
const ret = fn(ctx);
6767
if (ret === undefined) {
6868
throw new ERR_SYSTEM_ERROR(ctx);
6969
}

0 commit comments

Comments
 (0)