GeezerVison is showing github.com — os: cache homedir, remove getCheckedFunction · nodejs/node@c25716b
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboard +31Lines changed: 31 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 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 | +} |
Collapse file
Copy file name to clipboard +31Lines changed: 31 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 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 | +} |
Collapse file
Copy file name to clipboard +31Lines changed: 31 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 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 | +} |
Collapse file
Copy file name to clipboardExpand all lines: lib/os.js +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -61,9 +61,9 @@ const { |
61 | 61 | } = internalBinding('os'); |
62 | 62 |
|
63 | 63 | function getCheckedFunction(fn) { |
64 | | - return hideStackFrames(function checkError(...args) { |
| 64 | + return hideStackFrames(function checkError() { |
65 | 65 | const ctx = {}; |
66 | | - const ret = fn(...args, ctx); |
| 66 | + const ret = fn(ctx); |
67 | 67 | if (ret === undefined) { |
68 | 68 | throw new ERR_SYSTEM_ERROR(ctx); |
69 | 69 | } |
|