11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common.js');
31cb0ef41Sopenharmony_ciconst { File } = require('buffer');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, {
61cb0ef41Sopenharmony_ci  bytes: [128, 1024, 1024 ** 2],
71cb0ef41Sopenharmony_ci  n: [1e6],
81cb0ef41Sopenharmony_ci  operation: ['text', 'arrayBuffer'],
91cb0ef41Sopenharmony_ci});
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst options = {
121cb0ef41Sopenharmony_ci  lastModified: Date.now() - 1e6,
131cb0ef41Sopenharmony_ci};
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ciasync function run(n, bytes, operation) {
161cb0ef41Sopenharmony_ci  const buff = Buffer.allocUnsafe(bytes);
171cb0ef41Sopenharmony_ci  const source = new File(buff, 'dummy.txt', options);
181cb0ef41Sopenharmony_ci  bench.start();
191cb0ef41Sopenharmony_ci  for (let i = 0; i < n; i++) {
201cb0ef41Sopenharmony_ci    switch (operation) {
211cb0ef41Sopenharmony_ci      case 'text':
221cb0ef41Sopenharmony_ci        await source.text();
231cb0ef41Sopenharmony_ci        break;
241cb0ef41Sopenharmony_ci      case 'arrayBuffer':
251cb0ef41Sopenharmony_ci        await source.arrayBuffer();
261cb0ef41Sopenharmony_ci        break;
271cb0ef41Sopenharmony_ci    }
281cb0ef41Sopenharmony_ci  }
291cb0ef41Sopenharmony_ci  bench.end(n);
301cb0ef41Sopenharmony_ci}
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_cifunction main(conf) {
331cb0ef41Sopenharmony_ci  run(conf.n, conf.bytes, conf.operation).catch(console.log);
341cb0ef41Sopenharmony_ci}
35