MCPcopy Index your code
hub / github.com/react-hook-form/react-hook-form / main

Function main

scripts/bench.ts:163–207  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

161};
162
163async function main() {
164 if (!JSON_MODE)
165 process.stderr.write(`Running ${bench.tasks.length} scenarios…\n`);
166
167 await bench.run();
168
169 const rows: BenchRow[] = bench.tasks.map((t) => {
170 const r = (t as any).result;
171 return {
172 name: t.name,
173 opsPerSec: r?.throughput ? Math.round(r.throughput.mean) : 0,
174 avgUs: r?.latency ? r.latency.mean * 1000 : 0,
175 p99Us: r?.latency ? r.latency.p99 * 1000 : 0,
176 };
177 });
178
179 if (JSON_MODE) {
180 process.stdout.write(JSON.stringify(rows) + '\n');
181 return;
182 }
183
184 const tableRows = rows.map((r) => ({
185 Scenario: r.name,
186 'ops/sec': r.opsPerSec ? r.opsPerSec.toLocaleString() : 'ERROR',
187 'avg µs': r.avgUs.toFixed(2),
188 'p99 µs': r.p99Us.toFixed(2),
189 }));
190
191 console.log(`\n📊 react-hook-form — ${FIELDS}-field form benchmark\n`);
192 console.table(tableRows);
193
194 const noSub = rows.find(
195 (r) => r.name.includes('onChange') && r.name.includes('no sub'),
196 );
197 const withSub = rows.find(
198 (r) => r.name.includes('onChange') && r.name.includes('watch'),
199 );
200 if (noSub?.opsPerSec && withSub?.opsPerSec) {
201 const ratio = noSub.opsPerSec / withSub.opsPerSec;
202 console.log(
203 `\nonChange no-subscriber is ${ratio.toFixed(1)}× faster than with-subscriber`,
204 '(subscriber forces cloneObject)',
205 );
206 }
207}
208
209main();

Callers 1

bench.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…