MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / timeit

Function timeit

benchmarks/runners/run_mathjs.mjs:37–46  ·  view source on GitHub ↗
(fn)

Source from the content-addressed store, hash-verified

35 return s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2;
36}
37function timeit(fn) {
38 let t = performance.now();
39 fn();
40 const first = performance.now() - t;
41 const iterations = Math.min(50, Math.max(1, Math.round(150 / Math.max(first, 0.01))));
42 for (let i = 0; i < Math.min(3, iterations); i++) fn();
43 const times = [];
44 for (let i = 0; i < iterations; i++) { t = performance.now(); fn(); times.push(performance.now() - t); }
45 return { timeMs: median(times), minMs: Math.min(...times), iterations };
46}
47
48const mjPath = join(__dirname, '..', '.competitors', 'mathjs-host', 'node_modules', 'mathjs', 'lib', 'esm', 'index.js');
49const math = await import(mjPath);

Callers 1

run_mathjs.mjsFile · 0.70

Calls 3

fnFunction · 0.85
medianFunction · 0.70
roundMethod · 0.45

Tested by

no test coverage detected