MCPcopy Index your code
hub / github.com/nodejs/node / main

Function main

benchmark/calibrate-n.js:123–287  ·  view source on GitHub ↗
(n = startN)

Source from the content-addressed store, hash-verified

121}
122
123async 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--------------------------------------------------------
131Benchmark: ${benchmarkPath}
132--------------------------------------------------------
133What we are trying to find: The optimal number of iterations (n)
134that produces consistent benchmark results without wasting time.
135
136How it works:
1371. Run the benchmark multiple times with a specific n value
1382. Group results by configuration
1393. If overall CV is above 5% or any configuration has CV above 10%, increase n and try again
140
141Configuration:
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

Callers 1

calibrate-n.jsFile · 0.70

Calls 12

calculateStatsFunction · 0.85
styleTextFunction · 0.85
reduceMethod · 0.80
someMethod · 0.80
runBenchmarkFunction · 0.70
forEachMethod · 0.65
filterMethod · 0.65
logMethod · 0.45
pushMethod · 0.45
writeMethod · 0.45
entriesMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…