From 6858cf4a61bc45e6a05d22cb0aadf035ba1ebf48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Henriques?= Date: Tue, 4 Mar 2025 16:55:52 +0000 Subject: [PATCH 1/7] feat: add `measureAsyncFunction` function --- .../src/__tests__/measure-function.test.tsx | 14 +++++++ packages/measure/src/index.ts | 2 + .../measure/src/measure-async-function.tsx | 42 +++++++++++++++++++ packages/measure/src/measure-function.tsx | 9 +--- packages/measure/src/measure-helpers.tsx | 5 +++ packages/reassure/src/index.ts | 2 + test-apps/native/src/fib.perf.tsx | 13 +++++- 7 files changed, 79 insertions(+), 8 deletions(-) create mode 100644 packages/measure/src/measure-async-function.tsx diff --git a/packages/measure/src/__tests__/measure-function.test.tsx b/packages/measure/src/__tests__/measure-function.test.tsx index 3fc3dcf3d..b7b425900 100644 --- a/packages/measure/src/__tests__/measure-function.test.tsx +++ b/packages/measure/src/__tests__/measure-function.test.tsx @@ -1,5 +1,6 @@ import stripAnsi from 'strip-ansi'; import { measureFunction } from '../measure-function'; +import { measureAsyncFunction } from '../measure-async-function'; import { setHasShownFlagsOutput } from '../output'; // Exponentially slow function @@ -20,6 +21,19 @@ test('measureFunction captures results', async () => { expect(results.counts).toEqual([1]); }); +test('measureAsyncFunction captures results', async () => { + const fn = jest.fn(async () => { + const asyncLogic = () => Promise.resolve(5); + const result = await asyncLogic(); + fib(result); + }); + const results = await measureAsyncFunction(fn, { runs: 1, warmupRuns: 0, writeFile: false }); + + expect(fn).toHaveBeenCalledTimes(1); + expect(results.runs).toBe(1); + expect(results.counts).toEqual([1]); +}); + test('measureFunction runs specified number of times', async () => { const fn = jest.fn(() => fib(5)); const results = await measureFunction(fn, { runs: 20, warmupRuns: 0, writeFile: false }); diff --git a/packages/measure/src/index.ts b/packages/measure/src/index.ts index b39aaca76..c0a1899f2 100644 --- a/packages/measure/src/index.ts +++ b/packages/measure/src/index.ts @@ -1,6 +1,8 @@ export { configure, resetToDefaults } from './config'; export { measureRenders, measurePerformance } from './measure-renders'; export { measureFunction } from './measure-function'; +export { measureAsyncFunction } from './measure-async-function'; export type { MeasureRendersOptions } from './measure-renders'; export type { MeasureFunctionOptions } from './measure-function'; +export type { MeasureAsyncFunctionOptions } from './measure-async-function'; export type { MeasureType, MeasureResults } from './types'; diff --git a/packages/measure/src/measure-async-function.tsx b/packages/measure/src/measure-async-function.tsx new file mode 100644 index 000000000..c900595a8 --- /dev/null +++ b/packages/measure/src/measure-async-function.tsx @@ -0,0 +1,42 @@ +import { config } from './config'; +import type { MeasureResults } from './types'; +import { type RunResult, getCurrentTime, processRunResults } from './measure-helpers'; +import { showFlagsOutputIfNeeded, writeTestStats } from './output'; +import { MeasureFunctionOptions } from './measure-function'; + +export interface MeasureAsyncFunctionOptions extends MeasureFunctionOptions {} + +export async function measureAsyncFunction( + fn: () => Promise, + options?: MeasureAsyncFunctionOptions +): Promise { + const stats = await measureAsyncFunctionInternal(fn, options); + + if (options?.writeFile !== false) { + await writeTestStats(stats, 'function'); + } + + return stats; +} + +async function measureAsyncFunctionInternal( + fn: () => Promise, + options?: MeasureAsyncFunctionOptions +): Promise { + const runs = options?.runs ?? config.runs; + const warmupRuns = options?.warmupRuns ?? config.warmupRuns; + + showFlagsOutputIfNeeded(); + + const runResults: RunResult[] = []; + for (let i = 0; i < runs + warmupRuns; i += 1) { + const timeStart = getCurrentTime(); + await fn(); + const timeEnd = getCurrentTime(); + + const duration = timeEnd - timeStart; + runResults.push({ duration, count: 1 }); + } + + return processRunResults(runResults, warmupRuns); +} diff --git a/packages/measure/src/measure-function.tsx b/packages/measure/src/measure-function.tsx index 61620fb73..1c9b0bad2 100644 --- a/packages/measure/src/measure-function.tsx +++ b/packages/measure/src/measure-function.tsx @@ -1,7 +1,6 @@ -import { performance } from 'perf_hooks'; import { config } from './config'; import type { MeasureResults } from './types'; -import { type RunResult, processRunResults } from './measure-helpers'; +import { type RunResult, getCurrentTime, processRunResults } from './measure-helpers'; import { showFlagsOutputIfNeeded, writeTestStats } from './output'; export interface MeasureFunctionOptions { @@ -11,7 +10,7 @@ export interface MeasureFunctionOptions { } export async function measureFunction(fn: () => void, options?: MeasureFunctionOptions): Promise { - const stats = await measureFunctionInternal(fn, options); + const stats = measureFunctionInternal(fn, options); if (options?.writeFile !== false) { await writeTestStats(stats, 'function'); @@ -38,7 +37,3 @@ function measureFunctionInternal(fn: () => void, options?: MeasureFunctionOption return processRunResults(runResults, warmupRuns); } - -function getCurrentTime() { - return performance.now(); -} diff --git a/packages/measure/src/measure-helpers.tsx b/packages/measure/src/measure-helpers.tsx index c537c7a60..6096b7a2f 100644 --- a/packages/measure/src/measure-helpers.tsx +++ b/packages/measure/src/measure-helpers.tsx @@ -1,3 +1,4 @@ +import { performance } from 'perf_hooks'; import * as math from 'mathjs'; import type { MeasureResults } from './types'; @@ -6,6 +7,10 @@ export interface RunResult { count: number; } +export function getCurrentTime() { + return performance.now(); +} + export function processRunResults(inputResults: RunResult[], warmupRuns: number): MeasureResults { const warmupResults = inputResults.slice(0, warmupRuns); const results = inputResults.slice(warmupRuns); diff --git a/packages/reassure/src/index.ts b/packages/reassure/src/index.ts index e457a29c0..f57b0c375 100644 --- a/packages/reassure/src/index.ts +++ b/packages/reassure/src/index.ts @@ -1,6 +1,7 @@ export { measureRenders, measureFunction, + measureAsyncFunction, configure, resetToDefaults, measurePerformance, @@ -11,6 +12,7 @@ export type { MeasureResults, MeasureRendersOptions, MeasureFunctionOptions, + MeasureAsyncFunctionOptions, MeasureType, } from '@callstack/reassure-measure'; export type { diff --git a/test-apps/native/src/fib.perf.tsx b/test-apps/native/src/fib.perf.tsx index 1dc38255c..35647ee90 100644 --- a/test-apps/native/src/fib.perf.tsx +++ b/test-apps/native/src/fib.perf.tsx @@ -1,4 +1,7 @@ -import { measureFunction } from '@callstack/reassure-measure'; +import { + measureFunction, + measureAsyncFunction, +} from '@callstack/reassure-measure'; function fib(n: number): number { if (n <= 1) { @@ -22,4 +25,12 @@ describe('`fib` function', () => { test('fib(32)', async () => { await measureFunction(() => fib(32)); }); + + test('fib(32) async', async () => { + await measureAsyncFunction(async () => { + const asyncLogic = () => Promise.resolve(32); + const result = await asyncLogic(); + fib(result); + }); + }); }); From 87a64b4137c63834d6dfebdc48422a754ebddebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Henriques?= Date: Tue, 4 Mar 2025 17:27:11 +0000 Subject: [PATCH 2/7] chore: add documentation for `measureAsyncFunction` function --- README.md | 31 ++++++++++++++++++++++++ docusaurus/docs/api.md | 47 +++++++++++++++++++++++++++++++++++++ packages/reassure/README.md | 31 ++++++++++++++++++++++++ 3 files changed, 109 insertions(+) diff --git a/README.md b/README.md index 3bd3381f9..6e8064a86 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,8 @@ - [`MeasureRendersOptions` type](#measurerendersoptions-type) - [`measureFunction` function](#measurefunction-function) - [`MeasureFunctionOptions` type](#measurefunctionoptions-type) + - [`measureAsyncFunction` function](#measureasyncfunction-function) + - [`MeasureAsyncFunctionOptions` type](#measureasyncfunctionoptions-type) - [Configuration](#configuration) - [Default configuration](#default-configuration) - [`configure` function](#configure-function) @@ -397,11 +399,40 @@ async function measureFunction( interface MeasureFunctionOptions { runs?: number; warmupRuns?: number; + writeFile?: boolean; } ``` - **`runs`**: number of runs per series for the particular test - **`warmupRuns`**: number of additional warmup runs that will be done and discarded before the actual runs. +- **`writeFile`**: (default `true`) should write output to file. + +#### `measureAsyncFunction` function + +Allows you to wrap any **asynchronous** function, measure its execution times and write results to the output file. You can use optional `options` to customize aspects of the testing. Note: the execution count will always be one. + +> **Note**: Measuring asynchronous functions can be useful when, during its execution, they rely or need to get some data from async providers e.g. storage / network and we are purposely disconsidering their impact during the test as we want only to measure the rest of the function's logic. **With that in mind, make sure these providers are properly mocked during test environment so they don't pollute your measurements.** + +```ts +async function measureAsyncFunction( + fn: () => Promise, + options?: MeasureAsyncFunctionOptions +): Promise { +``` + +#### `MeasureAsyncFunctionOptions` type + +```ts +interface MeasureAsyncFunctionOptions { + runs?: number; + warmupRuns?: number; + writeFile?: boolean; +} +``` + +- **`runs`**: number of runs per series for the particular test +- **`warmupRuns`**: number of additional warmup runs that will be done and discarded before the actual runs. +- **`writeFile`**: (default `true`) should write output to file. ### Configuration diff --git a/docusaurus/docs/api.md b/docusaurus/docs/api.md index 814de7cdf..b876adf5e 100644 --- a/docusaurus/docs/api.md +++ b/docusaurus/docs/api.md @@ -99,6 +99,53 @@ interface MeasureFunctionOptions { - **`warmupRuns`**: number of additional warmup runs that will be done and discarded before the actual runs. - **`writeFile`**: (default `true`) should write output to file. +### `measureAsyncFunction` function {#measure-async-function} + +Allows you to wrap any **asynchronous** function, measure its performance and write results to the output file. You can use optional `options` to customize aspects of the testing. + +:::info + +Measuring asynchronous functions can be useful when, during its execution, they rely or need to get some data from async providers e.g. storage / network and we are purposely disconsidering their impact during the test as we want only to measure the rest of the function's logic. **With that in mind, make sure these providers are properly mocked during test environment so they don't pollute your measurements.** + +::: + +```ts +async function measureAsyncFunction( + fn: () => Promise, + options?: MeasureAsyncFunctionOptions, +): Promise { +``` + +#### Example {#measure-async-function-example} + +```ts +// sample.perf-test.tsx +import { measureAsyncFunction } from 'reassure'; +import { fib } from './fib'; + +test('fib 30', async () => { + await measureAsyncFunction(async () => { + const asyncLogic = () => Promise.resolve(30); + const result = await asyncLogic(); + fib(result); + }); +}); +``` + +### `MeasureAsyncFunctionOptions` type {#measure-async-function-options} + +```ts +interface MeasureAsyncFunctionOptions { + runs?: number; + warmupRuns?: number; + writeFile?: boolean; +} +``` + +- **`runs`**: number of runs per series for the particular test +- **`warmupRuns`**: number of additional warmup runs that will be done and discarded before the actual runs. +- **`writeFile`**: (default `true`) should write output to file. + ## Configuration ### Default configuration diff --git a/packages/reassure/README.md b/packages/reassure/README.md index 3bd3381f9..6e8064a86 100644 --- a/packages/reassure/README.md +++ b/packages/reassure/README.md @@ -43,6 +43,8 @@ - [`MeasureRendersOptions` type](#measurerendersoptions-type) - [`measureFunction` function](#measurefunction-function) - [`MeasureFunctionOptions` type](#measurefunctionoptions-type) + - [`measureAsyncFunction` function](#measureasyncfunction-function) + - [`MeasureAsyncFunctionOptions` type](#measureasyncfunctionoptions-type) - [Configuration](#configuration) - [Default configuration](#default-configuration) - [`configure` function](#configure-function) @@ -397,11 +399,40 @@ async function measureFunction( interface MeasureFunctionOptions { runs?: number; warmupRuns?: number; + writeFile?: boolean; } ``` - **`runs`**: number of runs per series for the particular test - **`warmupRuns`**: number of additional warmup runs that will be done and discarded before the actual runs. +- **`writeFile`**: (default `true`) should write output to file. + +#### `measureAsyncFunction` function + +Allows you to wrap any **asynchronous** function, measure its execution times and write results to the output file. You can use optional `options` to customize aspects of the testing. Note: the execution count will always be one. + +> **Note**: Measuring asynchronous functions can be useful when, during its execution, they rely or need to get some data from async providers e.g. storage / network and we are purposely disconsidering their impact during the test as we want only to measure the rest of the function's logic. **With that in mind, make sure these providers are properly mocked during test environment so they don't pollute your measurements.** + +```ts +async function measureAsyncFunction( + fn: () => Promise, + options?: MeasureAsyncFunctionOptions +): Promise { +``` + +#### `MeasureAsyncFunctionOptions` type + +```ts +interface MeasureAsyncFunctionOptions { + runs?: number; + warmupRuns?: number; + writeFile?: boolean; +} +``` + +- **`runs`**: number of runs per series for the particular test +- **`warmupRuns`**: number of additional warmup runs that will be done and discarded before the actual runs. +- **`writeFile`**: (default `true`) should write output to file. ### Configuration From f83eca807dda98da21400ef8d6074328ce7caabe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Jastrze=CC=A8bski?= Date: Wed, 5 Mar 2025 17:32:11 +0100 Subject: [PATCH 3/7] add changeset --- .changeset/popular-seahorses-provide.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/popular-seahorses-provide.md diff --git a/.changeset/popular-seahorses-provide.md b/.changeset/popular-seahorses-provide.md new file mode 100644 index 000000000..7d8e503ed --- /dev/null +++ b/.changeset/popular-seahorses-provide.md @@ -0,0 +1,6 @@ +--- +'reassure': minor +'@callstack/reassure-measure': minor +--- + +feat: add measureAsyncFunction From 6acf3c3514dd71b4e77c8714401d177d634bbd3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Jastrze=CC=A8bski?= Date: Wed, 5 Mar 2025 17:43:31 +0100 Subject: [PATCH 4/7] . --- test-apps/native/src/fib.perf.tsx | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/test-apps/native/src/fib.perf.tsx b/test-apps/native/src/fib.perf.tsx index 35647ee90..d5e22abf4 100644 --- a/test-apps/native/src/fib.perf.tsx +++ b/test-apps/native/src/fib.perf.tsx @@ -18,19 +18,29 @@ describe('`fib` function', () => { await measureFunction(() => fib(30)); }); + test('fib(30) async', async () => { + await measureAsyncFunction(async () => + Promise.resolve().then(() => fib(30)), + ); + }); + test('fib(31)', async () => { await measureFunction(() => fib(31)); }); + test('fib(31) async', async () => { + await measureAsyncFunction(async () => + Promise.resolve().then(() => fib(31)), + ); + }); + test('fib(32)', async () => { await measureFunction(() => fib(32)); }); test('fib(32) async', async () => { - await measureAsyncFunction(async () => { - const asyncLogic = () => Promise.resolve(32); - const result = await asyncLogic(); - fib(result); - }); + await measureAsyncFunction(async () => + Promise.resolve().then(() => fib(32)), + ); }); }); From 9eb930250173efece696e7bd09039679d384b67c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Jastrze=CC=A8bski?= Date: Wed, 5 Mar 2025 17:48:52 +0100 Subject: [PATCH 5/7] docs --- README.md | 2 +- docusaurus/docs/api.md | 4 ++-- packages/reassure/README.md | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6e8064a86..6f9e7302c 100644 --- a/README.md +++ b/README.md @@ -411,7 +411,7 @@ interface MeasureFunctionOptions { Allows you to wrap any **asynchronous** function, measure its execution times and write results to the output file. You can use optional `options` to customize aspects of the testing. Note: the execution count will always be one. -> **Note**: Measuring asynchronous functions can be useful when, during its execution, they rely or need to get some data from async providers e.g. storage / network and we are purposely disconsidering their impact during the test as we want only to measure the rest of the function's logic. **With that in mind, make sure these providers are properly mocked during test environment so they don't pollute your measurements.** +> **Note**: Measuring performance of asynchronous functions can be tricky. These functions often depend on external conditions like I/O operations, network requests, or storage access, which introduce unpredictable timing variations in your measurements. For stable and meaningful performance metrics, **always ensure all external calls are properly mocked in your test environment to avoid polluting your performance measurements with uncontrollable factors.** ```ts async function measureAsyncFunction( diff --git a/docusaurus/docs/api.md b/docusaurus/docs/api.md index b876adf5e..33dc5b75a 100644 --- a/docusaurus/docs/api.md +++ b/docusaurus/docs/api.md @@ -101,11 +101,11 @@ interface MeasureFunctionOptions { ### `measureAsyncFunction` function {#measure-async-function} -Allows you to wrap any **asynchronous** function, measure its performance and write results to the output file. You can use optional `options` to customize aspects of the testing. +Allows you to wrap any asynchronous function, measure its performance and write results to the output file. You can use optional `options` to customize aspects of the testing. :::info -Measuring asynchronous functions can be useful when, during its execution, they rely or need to get some data from async providers e.g. storage / network and we are purposely disconsidering their impact during the test as we want only to measure the rest of the function's logic. **With that in mind, make sure these providers are properly mocked during test environment so they don't pollute your measurements.** +Measuring performance of asynchronous functions can be tricky. These functions often depend on external conditions like I/O operations, network requests, or storage access, which introduce unpredictable timing variations in your measurements. For stable and meaningful performance metrics, **always ensure all external calls are properly mocked in your test environment to avoid polluting your performance measurements with uncontrollable factors.** ::: diff --git a/packages/reassure/README.md b/packages/reassure/README.md index 6e8064a86..6f9e7302c 100644 --- a/packages/reassure/README.md +++ b/packages/reassure/README.md @@ -411,7 +411,7 @@ interface MeasureFunctionOptions { Allows you to wrap any **asynchronous** function, measure its execution times and write results to the output file. You can use optional `options` to customize aspects of the testing. Note: the execution count will always be one. -> **Note**: Measuring asynchronous functions can be useful when, during its execution, they rely or need to get some data from async providers e.g. storage / network and we are purposely disconsidering their impact during the test as we want only to measure the rest of the function's logic. **With that in mind, make sure these providers are properly mocked during test environment so they don't pollute your measurements.** +> **Note**: Measuring performance of asynchronous functions can be tricky. These functions often depend on external conditions like I/O operations, network requests, or storage access, which introduce unpredictable timing variations in your measurements. For stable and meaningful performance metrics, **always ensure all external calls are properly mocked in your test environment to avoid polluting your performance measurements with uncontrollable factors.** ```ts async function measureAsyncFunction( From 2ddd040bd316a1cc3ec1ca2066723bc8176ce265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Henriques?= Date: Thu, 6 Mar 2025 07:38:20 +0000 Subject: [PATCH 6/7] chore: add 'async function' measure type --- packages/compare/src/type-schemas.ts | 4 ++-- packages/measure/src/measure-async-function.tsx | 2 +- packages/measure/src/types.ts | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/compare/src/type-schemas.ts b/packages/compare/src/type-schemas.ts index be5a34a45..56930112c 100644 --- a/packages/compare/src/type-schemas.ts +++ b/packages/compare/src/type-schemas.ts @@ -22,8 +22,8 @@ export const MeasureEntryScheme = z.object({ /** Name of the test scenario. */ name: z.string(), - /** Type of the measured characteristic (render, function execution). */ - type: z.enum(['render', 'function']).default('render'), + /** Type of the measured characteristic (render, function execution, async function execution). */ + type: z.enum(['render', 'function', 'async function']).default('render'), /** Number of times the measurement test was run. */ runs: z.number(), diff --git a/packages/measure/src/measure-async-function.tsx b/packages/measure/src/measure-async-function.tsx index c900595a8..6a536d423 100644 --- a/packages/measure/src/measure-async-function.tsx +++ b/packages/measure/src/measure-async-function.tsx @@ -13,7 +13,7 @@ export async function measureAsyncFunction( const stats = await measureAsyncFunctionInternal(fn, options); if (options?.writeFile !== false) { - await writeTestStats(stats, 'function'); + await writeTestStats(stats, 'async function'); } return stats; diff --git a/packages/measure/src/types.ts b/packages/measure/src/types.ts index a01e6e8e0..6711257f3 100644 --- a/packages/measure/src/types.ts +++ b/packages/measure/src/types.ts @@ -1,5 +1,5 @@ /** Type of measured performance characteristic. */ -export type MeasureType = 'render' | 'function'; +export type MeasureType = 'render' | 'function' | 'async function'; /** * Type representing the result of `measure*` functions. From 1df26af7e9453f403e321187ef134f1f484b80dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Henriques?= Date: Thu, 6 Mar 2025 11:31:24 +0000 Subject: [PATCH 7/7] chore: use Promise and fix examples --- README.md | 2 +- docusaurus/docs/api.md | 6 ++---- packages/measure/src/__tests__/measure-function.test.tsx | 5 ++--- packages/measure/src/measure-async-function.tsx | 4 ++-- packages/reassure/README.md | 2 +- 5 files changed, 8 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 6f9e7302c..9640a4dbc 100644 --- a/README.md +++ b/README.md @@ -415,7 +415,7 @@ Allows you to wrap any **asynchronous** function, measure its execution times an ```ts async function measureAsyncFunction( - fn: () => Promise, + fn: () => Promise, options?: MeasureAsyncFunctionOptions ): Promise { ``` diff --git a/docusaurus/docs/api.md b/docusaurus/docs/api.md index 33dc5b75a..939971e71 100644 --- a/docusaurus/docs/api.md +++ b/docusaurus/docs/api.md @@ -111,7 +111,7 @@ Measuring performance of asynchronous functions can be tricky. These functions o ```ts async function measureAsyncFunction( - fn: () => Promise, + fn: () => Promise, options?: MeasureAsyncFunctionOptions, ): Promise { ``` @@ -125,9 +125,7 @@ import { fib } from './fib'; test('fib 30', async () => { await measureAsyncFunction(async () => { - const asyncLogic = () => Promise.resolve(30); - const result = await asyncLogic(); - fib(result); + return Promise.resolve().then(() => fib(30)); }); }); ``` diff --git a/packages/measure/src/__tests__/measure-function.test.tsx b/packages/measure/src/__tests__/measure-function.test.tsx index b7b425900..6aa632c44 100644 --- a/packages/measure/src/__tests__/measure-function.test.tsx +++ b/packages/measure/src/__tests__/measure-function.test.tsx @@ -23,9 +23,8 @@ test('measureFunction captures results', async () => { test('measureAsyncFunction captures results', async () => { const fn = jest.fn(async () => { - const asyncLogic = () => Promise.resolve(5); - const result = await asyncLogic(); - fib(result); + await Promise.resolve(); + return fib(5); }); const results = await measureAsyncFunction(fn, { runs: 1, warmupRuns: 0, writeFile: false }); diff --git a/packages/measure/src/measure-async-function.tsx b/packages/measure/src/measure-async-function.tsx index 6a536d423..6bb51de54 100644 --- a/packages/measure/src/measure-async-function.tsx +++ b/packages/measure/src/measure-async-function.tsx @@ -7,7 +7,7 @@ import { MeasureFunctionOptions } from './measure-function'; export interface MeasureAsyncFunctionOptions extends MeasureFunctionOptions {} export async function measureAsyncFunction( - fn: () => Promise, + fn: () => Promise, options?: MeasureAsyncFunctionOptions ): Promise { const stats = await measureAsyncFunctionInternal(fn, options); @@ -20,7 +20,7 @@ export async function measureAsyncFunction( } async function measureAsyncFunctionInternal( - fn: () => Promise, + fn: () => Promise, options?: MeasureAsyncFunctionOptions ): Promise { const runs = options?.runs ?? config.runs; diff --git a/packages/reassure/README.md b/packages/reassure/README.md index 6f9e7302c..9640a4dbc 100644 --- a/packages/reassure/README.md +++ b/packages/reassure/README.md @@ -415,7 +415,7 @@ Allows you to wrap any **asynchronous** function, measure its execution times an ```ts async function measureAsyncFunction( - fn: () => Promise, + fn: () => Promise, options?: MeasureAsyncFunctionOptions ): Promise { ```