From: Ardis Lu Date: Mon, 17 Feb 2025 07:01:01 +0000 (-0800) Subject: Add JSDoc for benchmark utils X-Git-Tag: v0.1.0~46 X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=c44b1da63322cc62330c464b8c6f65f025cad966;p=csvio Add JSDoc for benchmark utils --- 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}`);