forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbench-mkdtempSync.js
43 lines (38 loc) · 934 Bytes
/
bench-mkdtempSync.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'use strict';
const common = require('../common');
const fs = require('fs');
const assert = require('assert');
const tmpdir = require('../../test/common/tmpdir');
const bench = common.createBenchmark(main, {
type: ['valid-string', 'valid-buffer', 'invalid'],
n: [1e4],
});
function main({ n, type }) {
tmpdir.refresh();
const options = { encoding: 'utf8' };
let prefix;
let out = true;
switch (type) {
case 'valid-string':
prefix = tmpdir.resolve(`${Date.now()}`);
break;
case 'valid-buffer':
prefix = Buffer.from(tmpdir.resolve(`${Date.now()}`));
break;
case 'invalid':
prefix = tmpdir.resolve('non-existent', 'foo', 'bar');
break;
default:
new Error('Invalid type');
}
bench.start();
for (let i = 0; i < n; i++) {
try {
out = fs.mkdtempSync(prefix, options);
} catch {
// do nothing
}
}
bench.end(n);
assert.ok(out);
}