2022-11-10 20:52:45 +00:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common.js');
|
|
|
|
const { File } = require('buffer');
|
|
|
|
|
|
|
|
const bench = common.createBenchmark(main, {
|
2023-09-22 11:52:57 +00:00
|
|
|
bytes: [128, 1024],
|
|
|
|
n: [1e3],
|
2023-01-29 18:13:35 +00:00
|
|
|
operation: ['text', 'arrayBuffer'],
|
2022-11-10 20:52:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|