Function measureExecutionDuration

  • Measures how long (in milliseconds) the given callback takes to run to completion. By default this is synchronous, but it will automatically switch to async and await the callback if it returns a promise.

    Type Parameters

    • T

    Parameters

    • callback: (() => T)
        • (): T
        • Returns T

    Returns T extends Promise<any>
        ? Promise<Duration<DurationUnit.Milliseconds>>
        : Duration<DurationUnit.Milliseconds>

    import {measureExecutionDuration} from '@augment-vir/common';

    const duration1 = measureExecutionDuration(() => {});
    const duration2 = await measureExecutionDuration(async () => {});