]> git.ardis.lu - csvio/commitdiff
Add JSDoc for benchmark utils
authorArdis Lu <ardisglu@gmail.com>
Mon, 17 Feb 2025 07:01:01 +0000 (23:01 -0800)
committerArdis Lu <ardisglu@gmail.com>
Mon, 17 Feb 2025 07:01:01 +0000 (23:01 -0800)
benchmark/utils.js

index 20b826a0ec515304ec762ff217cacad7b0584f7c..bed025d7785ff31558549362d4902292aea59534 100644 (file)
@@ -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}`);
This page took 0.039522 seconds and 4 git commands to generate.