はい、私は同様の問題を発見し、それは私には思えるreact-addons-perf
のみreact
上で動作し、react native
プロジェクトのために、あなたはreact native
libに内蔵されたツールであるRCTRenderingPerf
を使用することができます。私は、ネイティブ版を反応"react-native": "^0.45.1"
import PerfMonitor from 'react-native/Libraries/Performance/RCTRenderingPerf';
スタート測定
PerfMonitor.toggle();
PerfMonitor.start();
停止測定と印刷結果
PerfMonitor.stop();
であるあなたは、明示的に結果を印刷するためにprintメソッドを呼び出す必要はありませんstop()
は既にそれをカバーしています。
あなたは実行することによって、それを確認することができます。
...
_setIndex(idx){
PerfMonitor.toggle();
PerfMonitor.start();
this.setState({index:idx})
}
componentDidUpdate(){
PerfMonitor.stop();
}
render() {
return (
<View style={styles.container}>
<Text>Welcome to react-native {helloWorld()}</Text>
<Text>Open up App.js to start working on your app!</Text>
<Text>Changes you make will automatically reload.</Text>
<Text>Shake your phone to open the developer menu.</Text>
<Button title="click me to see profiling in console log" onPress={()=> this._setIndex(2)}/>
</View>
);
}
...
を確認Remote Debug JS
が上であることを確認し、その後、あなたはクロームコンソールに結果を見ることができます。
私は警告を追加します: 'PerfMonitor.toggle()'が一度だけ呼び出されていることを確認してください。私は '_setIndex'の外でそれを呼び出すでしょう –
ありがとう、これは私を悩ましていました。今働いて! – kevinl
@AmauryLietこれは非常に良い点です。 'PerfMonitor.toggle()'を 'componentWillMount()'に入れることができます。 –