(n, bytes, operation)
| 9 | }); |
| 10 | |
| 11 | async 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 | |
| 28 | function main(conf) { |
| 29 | run(conf.n, conf.bytes, conf.operation).catch(console.log); |