From c44b1da63322cc62330c464b8c6f65f025cad966 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sun, 16 Feb 2025 23:01:01 -0800 Subject: [PATCH] Add JSDoc for benchmark utils --- benchmark/utils.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/benchmark/utils.js b/benchmark/utils.js index 20b826a..bed025d 100644 --- a/benchmark/utils.js +++ b/benchmark/utils.js @@ -1,5 +1,11 @@ import { styleText } from 'node:util'; +/** + * Measure the time it tasks to execute `fn` and log the result to console. + * + * @param {string} name A label for the benchmark. + * @param {function} fn The function to measure. + */ export async function benchmark(name, fn) { performance.mark('start'); await fn(); @@ -15,6 +21,14 @@ export async function benchmark(name, fn) { performance.clearMeasures(); } +/** + * Measure the average time it takes for `fn` to execute across `iterations` number of executions and + * log the result to console. + * + * @param {string} name A label for the benchmark. + * @param {number} iterations The number of times to execute the function. + * @param {function} fn The function to benchmark. + */ export async function benchmarkIterations(name, iterations, fn) { for (let i = 0; i < iterations; i++) { performance.mark(`start:${i}`); -- 2.47.3