time the execution of a function.

  • Type Parameters

    • ARGS extends any[] = any[]

    Parameters

    • fn: ((...args: ARGS) => any)
        • (...args): any
        • Parameters

          Returns any

    • Rest...args: ARGS

    Returns number

    millisecond time for function execution.

    import { assertGreater, assertLess } from "jsr:@std/assert"

    const
    testFn = (a: number, b: number): number => { return a + b },
    delta_time = timeIt(testFn, 5, 10),
    log = `execution time: ${delta_time} ms`
    assertGreater(delta_time, 0) // computing a sum should take more than `0` milliseconds
    assertLess(delta_time, 2) // computing a sum should take less than `2` milliseconds