--- id: perf title: Performance Tools permalink: docs/perf.html layout: docs category: Add-Ons prev: create-fragment.html next: test-utils.html --- **Importing** ```javascript import Perf from 'react-addons-perf' // ES6 var Perf = require('react-addons-perf') // ES5 with npm var Perf = React.addons.Perf; // ES5 with react-with-addons.js // Usually importing Perf in ES6 with a module bundler // doesn't make Perf available as global and throws a // ReferenceError so create a global window.Perf = Perf; ``` ## Overview React is usually quite fast out of the box. However, in situations where you need to squeeze every ounce of performance out of your app, it provides a [shouldComponentUpdate()](/react/docs/react-component.html#shouldcomponentupdate) hook where you can add optimization hints to React's diff algorithm. In addition to giving you an overview of your app's overall performance, `Perf` is a profiling tool that tells you exactly where you need to put these hooks. See these articles for an introduction to React performance tooling: - ["How to Benchmark React Components"](https://medium.com/code-life/how-to-benchmark-react-components-the-quick-and-dirty-guide-f595baf1014c) - ["Performance Engineering with React"](http://benchling.engineering/performance-engineering-with-react/) - ["A Deep Dive into React Perf Debugging"](http://benchling.engineering/deep-dive-react-perf-debugging/) ### Development vs. Production Builds If you're benchmarking or seeing performance problems in your React apps, make sure you're testing with the [minified production build](/react/downloads.html). The development build includes extra warnings that are helpful when building your apps, but it is slower due to the extra bookkeeping it does. However, the perf tools described on this page only work when using the development build of React. Therefore, the profiler only serves to indicate the _relatively_ expensive parts of your app. ### Using Perf The `Perf` object can be used with React in development mode only. You should not include this bundle when building your app for production. #### Getting Measurements - [`start()`](#start) - [`stop()`](#stop) - [`getLastMeasurements()`](#getlastmeasurements) #### Printing Results The following methods use the measurements returned by [`Perf.getLastMeasurements()`](#getlastmeasurements) to pretty-print the result. - [`printInclusive()`](#printinclusive) - [`printExclusive()`](#printexclusive) - [`printWasted()`](#printwasted) - [`printOperations()`](#printoperations) - [`printDOM()`](#printdom) * * * ## Example Usage We will take simple example of a form which can be used to submit comments and then listing all comments. The example code is [available on GitHub](https://github.com/dhyey35/react-example-for-performance/blob/master/public/scripts/example.js). ```javascript import { Component } from 'react' import Perf from 'react-addons-perf' const Comment = (props) => (