({ inputLen, duration, type, algorithm })
| 22 | }; |
| 23 | |
| 24 | function main({ inputLen, duration, type, algorithm }) { |
| 25 | const buffer = Buffer.alloc(inputLen, fs.readFileSync(__filename)); |
| 26 | const chunk = type === 'buffer' ? buffer : buffer.toString('utf8'); |
| 27 | |
| 28 | const [createCompress, createUncompress] = algorithms[algorithm]; |
| 29 | const input = createCompress(); |
| 30 | const output = createUncompress(); |
| 31 | |
| 32 | let readFromOutput = 0; |
| 33 | input.pipe(output); |
| 34 | if (type === 'string') |
| 35 | output.setEncoding('utf8'); |
| 36 | output.on('data', (chunk) => readFromOutput += chunk.length); |
| 37 | |
| 38 | function write() { |
| 39 | input.write(chunk, write); |
| 40 | } |
| 41 | |
| 42 | bench.start(); |
| 43 | write(); |
| 44 | |
| 45 | setTimeout(() => { |
| 46 | // Give result in GBit/s, like the net benchmarks do |
| 47 | bench.end(readFromOutput * 8 / (1024 ** 3)); |
| 48 | |
| 49 | // Cut off writing the easy way. |
| 50 | input.write = () => {}; |
| 51 | }, duration * 1000); |
| 52 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…