mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
1a839f388e
PR-URL: https://github.com/nodejs/node/pull/49730 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
35 lines
737 B
JavaScript
35 lines
737 B
JavaScript
'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);
|
|
}
|