summaryrefslogtreecommitdiff
path: root/benchmark/blob/file.js
blob: 001de1be1157f9cef51fb5413c8611fb52c5800b (plain)
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, 1024 ** 2],
  n: [1e6],
  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);
}