Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(BREAKING) refactor: rename dropWorst option to warmupRuns #401

Merged
merged 2 commits into from
May 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/thirty-roses-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@callstack/reassure-measure': minor
'reassure': minor
---

(BREAKING) refactor: renamed `dropWorst` option to `warmupRuns` with slight change of logic behind it.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,14 @@ async function measurePerformance(ui: React.ReactElement, options?: MeasureOptio
```ts
interface MeasureOptions {
runs?: number;
dropWorst?: number;
warmupRuns?: number;
wrapper?: React.ComponentType<{ children: ReactElement }>;
scenario?: (view?: RenderResult) => Promise<any>;
}
```

- **`runs`**: number of runs per series for the particular test
- **`dropWorst`**: number of worst (highest) runs dropped from a test series
- **`warmupRuns`**: number of additional warmup runs that will be done and discarded before the actual runs (default 1).
- **`wrapper`**: React component, such as a `Provider`, which the `ui` will be wrapped with. Note: the render duration of the `wrapper` itself is excluded from the results, only the wrapped component is measured.
- **`scenario`**: a custom async function, which defines user interaction within the ui by utilized RNTL functions

Expand All @@ -405,7 +405,7 @@ of the `configure` function.
```ts
type Config = {
runs?: number;
dropWorst?: number;
warmupRuns?: number;
outputFile?: string;
verbose?: boolean;
testingLibrary?:
Expand All @@ -418,15 +418,15 @@ type Config = {
```ts
const defaultConfig: Config = {
runs: 10,
dropWorst: 1,
warmupRuns: 1,
outputFile: '.reassure/current.perf',
verbose: false,
testingLibrary: undefined, // Will try auto-detect first RNTL, then RTL
};
```

**`runs`**: number of repeated runs in a series per test (allows for higher accuracy by aggregating more data). Should be handled with care.
**`dropWorst`**: number of worst dropped results from the series per test (used to remove test run outliers)
- **`warmupRuns`**: number of additional warmup runs that will be done and discarded before the actual runs.
**`outputFile`**: name of the file the records will be saved to
**`verbose`**: make Reassure log more, e.g. for debugging purposes
**`testingLibrary`**: where to look for `render` and `cleanup` functions, supported values `'react-native'`, `'react'` or object providing custom `render` and `cleanup` functions
Expand Down
10 changes: 5 additions & 5 deletions docusaurus/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ test('Test with scenario', async () => {
```ts
interface MeasureOptions {
runs?: number;
dropWorst?: number;
warmupRuns?: number;
wrapper?: React.ComponentType<{ children: ReactElement }>;
scenario?: (view?: RenderResult) => Promise<any>;
}
```
- **`runs`**: number of runs per series for the particular test
- **`dropWorst`**: number of worst (highest) runs dropped from a test series
- **`warmupRuns`**: number of additional warmup runs that will be done and discarded before the actual runs.
- **`wrapper`**: React component, such as a `Provider`, which the `ui` will be wrapped with. Note: the render duration of the `wrapper` itself is excluded from the results, only the wrapped component is measured.
- **`scenario`**: a custom async function, which defines user interaction within the ui by utilized RNTL functions
Expand All @@ -61,7 +61,7 @@ of the `configure` function.
```ts
type Config = {
runs?: number;
dropWorst?: number;
warmupRuns?: number;
outputFile?: string;
verbose?: boolean;
testingLibrary?:
Expand All @@ -74,15 +74,15 @@ type Config = {
```ts
const defaultConfig: Config = {
runs: 10,
dropWorst: 1,
warmupRuns: 1,
outputFile: '.reassure/current.perf',
verbose: false,
testingLibrary: undefined, // Will try auto-detect first RNTL, then RTL
};
```
**`runs`**: number of repeated runs in a series per test (allows for higher accuracy by aggregating more data). Should be handled with care.
**`dropWorst`**: number of worst dropped results from the series per test (used to remove test run outliers)
- **`warmupRuns`**: number of additional warmup runs that will be done and discarded before the actual runs.
**`outputFile`**: name of the file the records will be saved to
**`verbose`**: make Reassure log more, e.g. for debugging purposes
**`testingLibrary`**: where to look for `render` and `cleanup` functions, supported values `'react-native'`, `'react'` or object providing custom `render` and `cleanup` functions
Expand Down
4 changes: 2 additions & 2 deletions packages/reassure-measure/src/__tests__/measure.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ test('processRunResults calculates correct means and stdevs', () => {
});
});

test('processRunResults applies dropWorst option', () => {
test('processRunResults applies warmupRuns option', () => {
const input = [
{ duration: 23, count: 1 },
{ duration: 20, count: 5 },
{ duration: 24, count: 5 },
{ duration: 22, count: 5 },
{ duration: 1000, count: 1 },
];

expect(processRunResults(input, 1)).toEqual({
Expand Down
4 changes: 2 additions & 2 deletions packages/reassure-measure/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ export type Cleanup = () => void;

type Config = {
runs: number;
dropWorst: number;
warmupRuns: number;
outputFile: string;
testingLibrary?: TestingLibrary;
};

const defaultConfig: Config = {
runs: 10,
dropWorst: 1,
warmupRuns: 1,
outputFile: process.env.REASSURE_OUTPUT_FILE ?? '.reassure/current.perf',
testingLibrary: undefined,
};
Expand Down
12 changes: 6 additions & 6 deletions packages/reassure-measure/src/measure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ logger.configure({

export interface MeasureOptions {
runs?: number;
dropWorst?: number;
warmupRuns?: number;
wrapper?: React.ComponentType<{ children: React.ReactElement }>;
scenario?: (screen: any) => Promise<any>;
}
Expand All @@ -31,15 +31,15 @@ export async function measurePerformance(
export async function measureRender(ui: React.ReactElement, options?: MeasureOptions): Promise<MeasureRenderResult> {
const runs = options?.runs ?? config.runs;
const scenario = options?.scenario;
const dropWorst = options?.dropWorst ?? config.dropWorst;
const warmupRuns = options?.warmupRuns ?? config.warmupRuns;

const { render, cleanup } = resolveTestingLibrary();

showFlagsOuputIfNeeded();

const runResults: RunResult[] = [];
let hasTooLateRender = false;
for (let i = 0; i < runs + dropWorst; i += 1) {
for (let i = 0; i < runs + warmupRuns; i += 1) {
let duration = 0;
let count = 0;
let isFinished = false;
Expand Down Expand Up @@ -75,7 +75,7 @@ export async function measureRender(ui: React.ReactElement, options?: MeasureOpt
);
}

return processRunResults(runResults, dropWorst);
return processRunResults(runResults, warmupRuns);
}

export function buildUiToRender(
Expand All @@ -97,9 +97,9 @@ interface RunResult {
count: number;
}

export function processRunResults(results: RunResult[], dropWorst: number) {
export function processRunResults(results: RunResult[], warmupRuns: number) {
results = results.slice(warmupRuns);
results.sort((first, second) => second.duration - first.duration); // duration DESC
results = results.slice(dropWorst);

const durations = results.map((result) => result.duration);
const meanDuration = math.mean(durations) as number;
Expand Down
10 changes: 5 additions & 5 deletions packages/reassure/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,14 @@ async function measurePerformance(ui: React.ReactElement, options?: MeasureOptio
```ts
interface MeasureOptions {
runs?: number;
dropWorst?: number;
warmupRuns?: number;
wrapper?: React.ComponentType<{ children: ReactElement }>;
scenario?: (view?: RenderResult) => Promise<any>;
}
```

- **`runs`**: number of runs per series for the particular test
- **`dropWorst`**: number of worst (highest) runs dropped from a test series
- **`warmupRuns`**: number of additional warmup runs that will be done and discarded before the actual runs.
- **`wrapper`**: React component, such as a `Provider`, which the `ui` will be wrapped with. Note: the render duration of the `wrapper` itself is excluded from the results, only the wrapped component is measured.
- **`scenario`**: a custom async function, which defines user interaction within the ui by utilized RNTL functions

Expand All @@ -405,7 +405,7 @@ of the `configure` function.
```ts
type Config = {
runs?: number;
dropWorst?: number;
warmupRuns?: number;
outputFile?: string;
verbose?: boolean;
testingLibrary?:
Expand All @@ -418,15 +418,15 @@ type Config = {
```ts
const defaultConfig: Config = {
runs: 10,
dropWorst: 1,
warmupRuns: 1,
outputFile: '.reassure/current.perf',
verbose: false,
testingLibrary: undefined, // Will try auto-detect first RNTL, then RTL
};
```

**`runs`**: number of repeated runs in a series per test (allows for higher accuracy by aggregating more data). Should be handled with care.
**`dropWorst`**: number of worst dropped results from the series per test (used to remove test run outliers)
- **`warmupRuns`**: number of additional warmup runs that will be done and discarded before the actual runs.
**`outputFile`**: name of the file the records will be saved to
**`verbose`**: make Reassure log more, e.g. for debugging purposes
**`testingLibrary`**: where to look for `render` and `cleanup` functions, supported values `'react-native'`, `'react'` or object providing custom `render` and `cleanup` functions
Expand Down