I would love to be able to start and stop the CPU Profiler in the Chrome developer window by making a javascript call. Something like:
chrome.cpuprofiler.start(); //do expensive operation chrome.cpuprofiler.stop();
Right now, the best I can do is:
Click "start profiling". //do expensive operation Click "stop profiling".
Is there even a shortcut key for this?
A JS profiler is an efficient tool to help you understand your code better – effectively finding, pinpointing and optimizing bottlenecks in your code. They're simple to run once you get used to the interface and it's likely you even have one built into your browser.
To profile a page load, click Record Page Load. DevTools automatically starts the recording and then automatically stops when it detects that the page has finished loading. To profile a running page, click Record, perform the actions that you want to profile, and then click Stop when you're finished.
To be able to visually identify what was going on when you profiled your website, Timeline is painted in different colors. JavaScript execution time is marked in yellow and it's called Scripting. The purple area shows the Rendering and the green parts of the Timeline show the Painting process.
You can!
An example:
if (window.console && window.console.profile) { console.profile("label for profile"); // insert code to profile here, // all function calls will be profiled console.profileEnd(); }
It also works on Safari, and with Firebug in Firefox.
Note: You can't use profile to time code that does not make a function call: if your code above is simply a for loop then the profiler won't find anything to profile. Use console.time()
and console.timeEnd()
to benchmark pure loops or code that does not call a function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With