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.

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