| 85 | }; |
| 86 | |
| 87 | const main = async function () { |
| 88 | const tests = [20000, 200000, 2000000, 20000000, 200000000].map((length) => ({ |
| 89 | length: length, |
| 90 | target: path.join(os.tmpdir(), `data-${length}.csv`), |
| 91 | })); |
| 92 | const report = reporter(); |
| 93 | await Promise.all( |
| 94 | tests.map(async function ({ length, target }) { |
| 95 | const time = process.hrtime(); |
| 96 | await write(length, target); |
| 97 | const [seconds] = process.hrtime(time); |
| 98 | console.log(`File ${target} created in ${seconds} seconds`); |
| 99 | }), |
| 100 | ); |
| 101 | await Promise.all( |
| 102 | tests.map(async function ({ length, target }) { |
| 103 | const hrtime = process.hrtime(); |
| 104 | await read(length, target); |
| 105 | const [seconds, hrtime_nanoseconds] = process.hrtime(hrtime); |
| 106 | const nanoseconds = seconds * NS_PER_SEC + hrtime_nanoseconds; |
| 107 | const throughput = Math.round((length / nanoseconds) * NS_PER_SEC); |
| 108 | console.log( |
| 109 | "Benchmark time:", |
| 110 | `${nanoseconds} nanoseconds (${seconds} seconds)`, |
| 111 | ); |
| 112 | console.log( |
| 113 | "Benchmark throughput:", |
| 114 | Math.round(throughput), |
| 115 | "records per second", |
| 116 | ); |
| 117 | report(length, nanoseconds, throughput); |
| 118 | }), |
| 119 | ); |
| 120 | await Promise.all( |
| 121 | tests.map(async function ({ target }) { |
| 122 | await dispose(target); |
| 123 | }), |
| 124 | ); |
| 125 | const results = report(); |
| 126 | print(results); |
| 127 | }; |
| 128 | |
| 129 | main(); |
| 130 | |