(n = startN)
| 121 | } |
| 122 | |
| 123 | async function main(n = startN) { |
| 124 | let increaseCount = 0; |
| 125 | let bestN = n; |
| 126 | let bestCV = Infinity; |
| 127 | let bestGroupStats = null; |
| 128 | |
| 129 | console.log(` |
| 130 | -------------------------------------------------------- |
| 131 | Benchmark: ${benchmarkPath} |
| 132 | -------------------------------------------------------- |
| 133 | What we are trying to find: The optimal number of iterations (n) |
| 134 | that produces consistent benchmark results without wasting time. |
| 135 | |
| 136 | How it works: |
| 137 | 1. Run the benchmark multiple times with a specific n value |
| 138 | 2. Group results by configuration |
| 139 | 3. If overall CV is above 5% or any configuration has CV above 10%, increase n and try again |
| 140 | |
| 141 | Configuration: |
| 142 | - Starting n: ${n.toLocaleString()} iterations |
| 143 | - Runs per n value: ${runs} |
| 144 | - Target CV threshold: ${cvThreshold * 100}% (lower CV = more stable results) |
| 145 | - Max increases: ${maxIncreases} |
| 146 | - Increase factor: ${increaseFactor}x`); |
| 147 | |
| 148 | while (increaseCount < maxIncreases) { |
| 149 | console.log(`\nTesting with n=${n}:`); |
| 150 | |
| 151 | const resultsData = []; |
| 152 | for (let i = 0; i < runs; i++) { |
| 153 | const results = await runBenchmark(n); |
| 154 | // Each run might return multiple results (one per configuration) |
| 155 | if (Array.isArray(results) && results.length > 0) { |
| 156 | resultsData.push(...results); |
| 157 | } else if (results) { |
| 158 | resultsData.push(results); |
| 159 | } |
| 160 | process.stdout.write('.'); |
| 161 | } |
| 162 | process.stdout.write('\n'); |
| 163 | |
| 164 | const groupedResults = {}; |
| 165 | resultsData.forEach((result) => { |
| 166 | if (!result || !result.conf) return; |
| 167 | |
| 168 | const confKey = JSON.stringify(result.conf); |
| 169 | groupedResults[confKey] ||= { |
| 170 | conf: result.conf, |
| 171 | rates: [], |
| 172 | }; |
| 173 | |
| 174 | groupedResults[confKey].rates.push(result.rate); |
| 175 | }); |
| 176 | |
| 177 | const groupStats = []; |
| 178 | for (const [confKey, group] of Object.entries(groupedResults)) { |
| 179 | console.log(`\nConfiguration: ${JSON.stringify(group.conf)}`); |
| 180 |
no test coverage detected
searching dependent graphs…