TS-Scribe - v1.2.0
    Preparing search index...

    Function benchmark

    • Benchmarks an async function, measuring execution time and the byte size of its result.

      Use iterations to average results across multiple runs, reducing noise from JIT warm-up and GC pauses. Set log: true for a console summary or supply BenchmarkOptions.onBenchmarkComplete for programmatic access to the BenchmarkInfo.

      Type Parameters

      • T

      Parameters

      • fn: () => Promise<T>

        The async function to benchmark.

      • Optionaloptions: BenchmarkOptions<T>

        Configuration options for the benchmark.

      Returns Promise<T>

      A Promise resolving to the result of the final iteration.

      Propagates any rejection thrown by fn.

      const data = await benchmark(async () => fetchData(), {
      label: 'fetchData',
      iterations: 10,
      log: true,
      });
    • Benchmarks a synchronous function, measuring execution time and the byte size of its result.

      Use iterations to average results across multiple runs, reducing noise from JIT warm-up and GC pauses. Set log: true for a console summary or supply BenchmarkOptions.onBenchmarkComplete for programmatic access to the BenchmarkInfo.

      Type Parameters

      • T

      Parameters

      • fn: () => T

        The synchronous function to benchmark.

      • Optionaloptions: BenchmarkOptions<T>

        Configuration options for the benchmark.

      Returns T

      The result of the final iteration.

      Propagates any error thrown by fn.

      const result = benchmark(() => processData(input), {
      label: 'processData',
      iterations: 1000,
      log: true,
      });