• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common.js');
3const { File } = require('buffer');
4
5const bench = common.createBenchmark(main, {
6  bytes: [128, 1024, 1024 ** 2],
7  n: [1e6],
8  operation: ['text', 'arrayBuffer'],
9});
10
11const options = {
12  lastModified: Date.now() - 1e6,
13};
14
15async function run(n, bytes, operation) {
16  const buff = Buffer.allocUnsafe(bytes);
17  const source = new File(buff, 'dummy.txt', options);
18  bench.start();
19  for (let i = 0; i < n; i++) {
20    switch (operation) {
21      case 'text':
22        await source.text();
23        break;
24      case 'arrayBuffer':
25        await source.arrayBuffer();
26        break;
27    }
28  }
29  bench.end(n);
30}
31
32function main(conf) {
33  run(conf.n, conf.bytes, conf.operation).catch(console.log);
34}
35