forked from mrsone40/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.js
More file actions
34 lines (30 loc) · 737 Bytes
/
file.js
File metadata and controls
34 lines (30 loc) · 737 Bytes
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
'use strict';
const common = require('../common.js');
const { File } = require('buffer');
const bench = common.createBenchmark(main, {
bytes: [128, 1024],
n: [1e3],
operation: ['text', 'arrayBuffer'],
});
const options = {
lastModified: Date.now() - 1e6,
};
async function run(n, bytes, operation) {
const buff = Buffer.allocUnsafe(bytes);
const source = new File(buff, 'dummy.txt', options);
bench.start();
for (let i = 0; i < n; i++) {
switch (operation) {
case 'text':
await source.text();
break;
case 'arrayBuffer':
await source.arrayBuffer();
break;
}
}
bench.end(n);
}
function main(conf) {
run(conf.n, conf.bytes, conf.operation).catch(console.log);
}