import { round } from "../../math" /** * 创建一个秒表函数,秒表函数每次执行会返回执行时到创建时的时差 * @param highPrecision 高精度(使用 performance.now() ) * * @example * let st = stopwatch() * await sleep(100) * st() // 100 * await sleep(100) * st() // 200 */ export function stopwatch(highPrecision?: boolean) { let start = highPrecision ? performance.now() : new Date().getTime() return function () { let now = highPrecision ? performance.now() : new Date().getTime() return round(now - start, 2) } }