@oazmi/kitchensink - v0.9.13
    Preparing search index...

    Function asyncTimeIt

    • asynchronously time the execution of an async function.

      if you are going to provide a synchronous function with certainty, then you might be better off using timeIt instead.

      Type Parameters

      • ARGS extends any[] = any[]

      Parameters

      Returns Promise<number>

      millisecond time for function execution.

      import {
      assertLessOrEqual as assertLe,
      assertGreaterOrEqual as assertGe,
      } from "jsr:@std/assert"

      const asyncTestFn = async (a: number, b: number): Promise<number> => new Promise((resolve) => {
      setTimeout(() => { resolve(a + b) }, 300)
      })
      const
      delta_time = await asyncTimeIt(asyncTestFn, 5, 10),
      log = `execution time: ${delta_time} ms`

      assertGe(delta_time, 290) // completing the promise should take more than `290` milliseconds
      assertLe(delta_time, 400) // completing the promise should take less than `400` milliseconds