({ len, duration, concurrent, encoding })
| 18 | }); |
| 19 | |
| 20 | function main({ len, duration, concurrent, encoding }) { |
| 21 | try { |
| 22 | fs.unlinkSync(filename); |
| 23 | } catch { |
| 24 | // Continue regardless of error. |
| 25 | } |
| 26 | let data = Buffer.alloc(len, 'x'); |
| 27 | fs.writeFileSync(filename, data); |
| 28 | data = null; |
| 29 | |
| 30 | let reads = 0; |
| 31 | let waitConcurrent = 0; |
| 32 | |
| 33 | const startedAt = Date.now(); |
| 34 | const endAt = startedAt + (duration * 1000); |
| 35 | |
| 36 | bench.start(); |
| 37 | |
| 38 | function read() { |
| 39 | fs.readFile(filename, encoding, afterRead); |
| 40 | } |
| 41 | |
| 42 | function stop() { |
| 43 | bench.end(reads); |
| 44 | |
| 45 | try { |
| 46 | fs.unlinkSync(filename); |
| 47 | } catch { |
| 48 | // Continue regardless of error. |
| 49 | } |
| 50 | |
| 51 | process.exit(0); |
| 52 | } |
| 53 | |
| 54 | function afterRead(er, data) { |
| 55 | if (er) { |
| 56 | throw er; |
| 57 | } |
| 58 | |
| 59 | if (data.length !== len) |
| 60 | throw new Error('wrong number of bytes returned'); |
| 61 | |
| 62 | reads++; |
| 63 | const benchEnded = Date.now() >= endAt; |
| 64 | |
| 65 | if (benchEnded && (++waitConcurrent) === concurrent) { |
| 66 | stop(); |
| 67 | } else if (!benchEnded) { |
| 68 | read(); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | for (let i = 0; i < concurrent; i++) read(); |
| 73 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…