@callstack/reassure-measure
Advanced tools
Comparing version 0.4.1 to 0.5.0
@@ -8,2 +8,3 @@ "use strict"; | ||
exports.measureRender = measureRender; | ||
exports.processRunResults = processRunResults; | ||
var React = _interopRequireWildcard(require("react")); | ||
@@ -31,6 +32,2 @@ var math = _interopRequireWildcard(require("mathjs")); | ||
const dropWorst = (options === null || options === void 0 ? void 0 : options.dropWorst) ?? _config.config.dropWorst; | ||
let entries = []; | ||
let hasTooLateRender = false; | ||
const wrappedUi = wrapper ? wrapper(ui) : ui; | ||
(0, _output.showFlagsOuputIfNeeded)(); | ||
const { | ||
@@ -40,2 +37,5 @@ render, | ||
} = (0, _testingLibrary.resolveTestingLibrary)(); | ||
(0, _output.showFlagsOuputIfNeeded)(); | ||
const runResults = []; | ||
let hasTooLateRender = false; | ||
for (let i = 0; i < runs + dropWorst; i += 1) { | ||
@@ -53,6 +53,8 @@ var _global$gc, _global; | ||
}; | ||
const screen = render( /*#__PURE__*/React.createElement(React.Profiler, { | ||
id: "Test", | ||
const uiWithProfiler = /*#__PURE__*/React.createElement(React.Profiler, { | ||
id: "REASSURE_ROOT", | ||
onRender: handleRender | ||
}, wrappedUi)); | ||
}, ui); | ||
const uiToRender = wrapper ? wrapper(uiWithProfiler) : uiWithProfiler; | ||
const screen = render(uiToRender); | ||
if (scenario) { | ||
@@ -64,3 +66,3 @@ await scenario(screen); | ||
(_global$gc = (_global = global).gc) === null || _global$gc === void 0 ? void 0 : _global$gc.call(_global); | ||
entries.push({ | ||
runResults.push({ | ||
duration, | ||
@@ -74,14 +76,15 @@ count | ||
} | ||
// Drop worst measurements outliers (usually warm up runs) | ||
entries.sort((first, second) => second.duration - first.duration); // duration DESC | ||
entries = entries.slice(dropWorst); | ||
const durations = entries.map(entry => entry.duration); | ||
return processRunResults(runResults, dropWorst); | ||
} | ||
function processRunResults(results, dropWorst) { | ||
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); | ||
const stdevDuration = math.std(...durations); | ||
const counts = entries.map(entry => entry.count); | ||
const counts = results.map(result => result.count); | ||
const meanCount = math.mean(counts); | ||
const stdevCount = math.std(...counts); | ||
return { | ||
runs, | ||
runs: results.length, | ||
meanDuration, | ||
@@ -88,0 +91,0 @@ stdevDuration, |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.clearTestStats = clearTestStats; | ||
exports.resetHasShownFlagsOutput = resetHasShownFlagsOutput; | ||
exports.showFlagsOuputIfNeeded = showFlagsOuputIfNeeded; | ||
@@ -37,5 +38,5 @@ exports.writeTestStats = writeTestStats; | ||
} | ||
let hasShowFlagsOutput = false; | ||
let hasShownFlagsOutput = false; | ||
function showFlagsOuputIfNeeded() { | ||
if (hasShowFlagsOutput) { | ||
if (hasShownFlagsOutput) { | ||
return; | ||
@@ -48,4 +49,7 @@ } | ||
} | ||
hasShowFlagsOutput = true; | ||
hasShownFlagsOutput = true; | ||
} | ||
function resetHasShownFlagsOutput() { | ||
hasShownFlagsOutput = false; | ||
} | ||
//# sourceMappingURL=output.js.map |
@@ -21,6 +21,2 @@ import * as React from 'react'; | ||
const dropWorst = (options === null || options === void 0 ? void 0 : options.dropWorst) ?? config.dropWorst; | ||
let entries = []; | ||
let hasTooLateRender = false; | ||
const wrappedUi = wrapper ? wrapper(ui) : ui; | ||
showFlagsOuputIfNeeded(); | ||
const { | ||
@@ -30,2 +26,5 @@ render, | ||
} = resolveTestingLibrary(); | ||
showFlagsOuputIfNeeded(); | ||
const runResults = []; | ||
let hasTooLateRender = false; | ||
for (let i = 0; i < runs + dropWorst; i += 1) { | ||
@@ -43,6 +42,8 @@ var _global$gc, _global; | ||
}; | ||
const screen = render( /*#__PURE__*/React.createElement(React.Profiler, { | ||
id: "Test", | ||
const uiWithProfiler = /*#__PURE__*/React.createElement(React.Profiler, { | ||
id: "REASSURE_ROOT", | ||
onRender: handleRender | ||
}, wrappedUi)); | ||
}, ui); | ||
const uiToRender = wrapper ? wrapper(uiWithProfiler) : uiWithProfiler; | ||
const screen = render(uiToRender); | ||
if (scenario) { | ||
@@ -54,3 +55,3 @@ await scenario(screen); | ||
(_global$gc = (_global = global).gc) === null || _global$gc === void 0 ? void 0 : _global$gc.call(_global); | ||
entries.push({ | ||
runResults.push({ | ||
duration, | ||
@@ -64,14 +65,15 @@ count | ||
} | ||
// Drop worst measurements outliers (usually warm up runs) | ||
entries.sort((first, second) => second.duration - first.duration); // duration DESC | ||
entries = entries.slice(dropWorst); | ||
const durations = entries.map(entry => entry.duration); | ||
return processRunResults(runResults, dropWorst); | ||
} | ||
export function processRunResults(results, dropWorst) { | ||
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); | ||
const stdevDuration = math.std(...durations); | ||
const counts = entries.map(entry => entry.count); | ||
const counts = results.map(result => result.count); | ||
const meanCount = math.mean(counts); | ||
const stdevCount = math.std(...counts); | ||
return { | ||
runs, | ||
runs: results.length, | ||
meanDuration, | ||
@@ -78,0 +80,0 @@ stdevDuration, |
@@ -26,5 +26,5 @@ import * as fs from 'fs/promises'; | ||
} | ||
let hasShowFlagsOutput = false; | ||
let hasShownFlagsOutput = false; | ||
export function showFlagsOuputIfNeeded() { | ||
if (hasShowFlagsOutput) { | ||
if (hasShownFlagsOutput) { | ||
return; | ||
@@ -37,4 +37,7 @@ } | ||
} | ||
hasShowFlagsOutput = true; | ||
hasShownFlagsOutput = true; | ||
} | ||
export function resetHasShownFlagsOutput() { | ||
hasShownFlagsOutput = false; | ||
} | ||
//# sourceMappingURL=output.js.map |
@@ -11,2 +11,16 @@ import * as React from 'react'; | ||
export declare function measureRender(ui: React.ReactElement, options?: MeasureOptions): Promise<MeasureRenderResult>; | ||
interface RunResult { | ||
duration: number; | ||
count: number; | ||
} | ||
export declare function processRunResults(results: RunResult[], dropWorst: number): { | ||
runs: number; | ||
meanDuration: number; | ||
stdevDuration: number; | ||
durations: number[]; | ||
meanCount: number; | ||
stdevCount: number; | ||
counts: number[]; | ||
}; | ||
export {}; | ||
//# sourceMappingURL=measure.d.ts.map |
@@ -5,2 +5,3 @@ import type { MeasureRenderResult } from './types'; | ||
export declare function showFlagsOuputIfNeeded(): void; | ||
export declare function resetHasShownFlagsOutput(): void; | ||
//# sourceMappingURL=output.d.ts.map |
{ | ||
"name": "@callstack/reassure-measure", | ||
"version": "0.4.1", | ||
"version": "0.5.0", | ||
"description": "Performance measurement library for React and React Native", | ||
@@ -13,3 +13,2 @@ "main": "lib/commonjs/index", | ||
"lib", | ||
"!lib/typescript/examples", | ||
"!**/__tests__", | ||
@@ -20,2 +19,3 @@ "!**/__fixtures__", | ||
"scripts": { | ||
"test": "jest", | ||
"build": "bob build" | ||
@@ -44,2 +44,5 @@ }, | ||
}, | ||
"devDependencies": { | ||
"react-native": "0.71.4" | ||
}, | ||
"peerDependencies": { | ||
@@ -46,0 +49,0 @@ "react": "*" |
@@ -29,6 +29,6 @@ import * as fs from 'fs/promises'; | ||
let hasShowFlagsOutput = false; | ||
let hasShownFlagsOutput = false; | ||
export function showFlagsOuputIfNeeded() { | ||
if (hasShowFlagsOutput) { | ||
if (hasShownFlagsOutput) { | ||
return; | ||
@@ -47,3 +47,7 @@ } | ||
hasShowFlagsOutput = true; | ||
hasShownFlagsOutput = true; | ||
} | ||
export function resetHasShownFlagsOutput() { | ||
hasShownFlagsOutput = false; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53499
786
1