@pathmaker-digital/pmd-utilities - v2.2.6
    Preparing search index...

    Function measurePerformance

    • Measures the performance of an asynchronous function by timing its execution.

      Type Parameters

      • T

        The return type of the asynchronous function.

      Parameters

      • label: string

        A label to identify the measurement in the console log.

      • fn: () => Promise<T>

        The asynchronous function to be measured.

      Returns Promise<T>

      A promise that resolves to the result of the asynchronous function.

      async function fetchData() {
      // Simulate an API call
      return new Promise((resolve) => setTimeout(() => resolve("data"), 1000));
      }

      const result = await measurePerformance("Fetch Data", fetchData);
      console.log(result); // Outputs: "data"