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