diff --git a/.flowconfig b/.flowconfig index cf05611e..a5a41701 100644 --- a/.flowconfig +++ b/.flowconfig @@ -3,7 +3,6 @@ [ignore] /.*/__tests__/.* -/packages/benchmarks/.* /packages/.*/dist/.* /website/.* .*/node_modules/babel-plugin-transform-react-remove-prop-types/* diff --git a/packages/benchmarks/src/app/App.js b/packages/benchmarks/src/app/App.js index 7cf7b222..d849de82 100644 --- a/packages/benchmarks/src/app/App.js +++ b/packages/benchmarks/src/app/App.js @@ -100,6 +100,8 @@ export default class App extends Component { libraryName={r.libraryName} libraryVersion={r.libraryVersion} mean={r.mean} + meanLayout={r.meanLayout} + meanScripting={r.meanScripting} runTime={r.runTime} sampleCount={r.sampleCount} stdDev={r.stdDev} @@ -130,6 +132,7 @@ export default class App extends Component { ): boolean => { switch (type) { // Render every odd iteration (first, third, etc) @@ -66,7 +66,8 @@ const sortNumbers = (a: number, b: number): number => a - b; type BenchmarkPropsType = { component: typeof React.Component, - getComponentProps?: Function, + forceLayout?: boolean, + getComponentProps: Function, onComplete: (x: BenchResultsType) => void, sampleCount: number, timeout: number, @@ -84,13 +85,13 @@ type BenchmarkStateType = { * TODO: documentation */ export default class Benchmark extends Component { + _raf: ?Function; _startTime: number; _samples: Array; static displayName = 'Benchmark'; static defaultProps = { - getComponentProps: () => emptyObject, sampleCount: 50, timeout: 10000, // 10 seconds type: BenchmarkType.MOUNT @@ -101,8 +102,9 @@ export default class Benchmark extends Component ({ componentProps: nextProps.getComponentProps(state.cycle) })); + if (nextProps) { + this.setState(state => ({ componentProps: nextProps.getComponentProps(state.cycle) })); + } } componentWillUpdate(nextProps: BenchmarkPropsType, nextState: BenchmarkStateType) { @@ -121,11 +125,20 @@ export default class Benchmark extends Component : null; } @@ -162,15 +175,18 @@ export default class Benchmark extends Component { + this._raf = window.requestAnimationFrame(() => { this.setState((state: BenchmarkStateType) => ({ cycle: state.cycle + 1, componentProps @@ -182,10 +198,16 @@ export default class Benchmark extends Component, - { start, end: endTime }: SampleTimingType + { scriptingStart, scriptingEnd, layoutStart, layoutEnd }: SampleTimingType ): Array => { - const end = endTime || 0; - memo.push({ start, end, elapsed: end - start }); + memo.push({ + start: scriptingStart, + end: layoutEnd || scriptingEnd || 0, + scriptingStart, + scriptingEnd: scriptingEnd || 0, + layoutStart, + layoutEnd + }); return memo; }, [] @@ -199,11 +221,13 @@ export default class Benchmark extends Component ({ running: false, cycle: 0 })); const runTime = endTime - this._startTime; - const sortedElapsedTimes = samples - .map(({ elapsed }: { elapsed: number }): number => elapsed) + const sortedElapsedTimes = samples.map(({ start, end }) => end - start).sort(sortNumbers); + const sortedScriptingElapsedTimes = samples + .map(({ scriptingStart, scriptingEnd }) => scriptingEnd - scriptingStart) + .sort(sortNumbers); + const sortedLayoutElapsedTimes = samples + .map(({ layoutStart, layoutEnd }) => (layoutEnd || 0) - (layoutStart || 0)) .sort(sortNumbers); - const mean = getMean(sortedElapsedTimes); - const stdDev = getStdDev(sortedElapsedTimes); onComplete({ startTime: this._startTime, @@ -214,8 +238,10 @@ export default class Benchmark extends Component {fmt(mean)} ±{fmt(stdDev)} ms - - Σ = - {Math.round(runTime)} ms + + (S/L) {fmt(meanScripting)} / {fmt(meanLayout)} ms ) : ( diff --git a/packages/benchmarks/src/app/Text.js b/packages/benchmarks/src/app/Text.js index a284ee6f..451e729b 100644 --- a/packages/benchmarks/src/app/Text.js +++ b/packages/benchmarks/src/app/Text.js @@ -1,9 +1,5 @@ /* eslint-disable react/prop-types */ -/** - * @flow - */ - import { bool } from 'prop-types'; import React from 'react'; import { StyleSheet, Text } from 'react-native'; diff --git a/packages/benchmarks/src/impl.js b/packages/benchmarks/src/impl.js index 504527b3..fae2d0e5 100644 --- a/packages/benchmarks/src/impl.js +++ b/packages/benchmarks/src/impl.js @@ -1,5 +1,3 @@ -/* @flow */ - import { type Component } from 'react'; import packageJson from '../package.json';