Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Profiling JavaScript without crashing your browser

So tried my hand at profiling some code and I figured the easiest way to do it (at least on Firefox) was to use either console's time/timeEnd or profile/profileEnd, and I tried both.

The problem I have is with the number of runs I can do before Firefox crashes on me. Now I won't paste the code here because it's typical benchmarking code (and it's very messy), but obviously the gist of it is that it runs functions (a test is represented with a function), logging their execution time for a certain number of runs.

Now with for example, 5e4 it sorta works but I don't think it's enough to spot (very) micro optimizations, but more than that, it crashes.

So how do you profile your JavaScript? Because this way, it's barely feasible.

like image 358
Andreas Grech Avatar asked Apr 24 '11 09:04

Andreas Grech


People also ask

What is browser profiling?

Think of profiles as different identifies you can switch between. They gather up all the usual browsing data—passwords, bookmarks, your browsing history—and keep them in separate buckets. Perhaps the most obvious way to use them is to have one for work stuff and one for personal stuff, but there are other uses too.

Why does Javascript keep crashing?

Most unpredictable crashes in Javascript are caused by memory leaks - objects that are still stored in memory and not being picked up by the garbage collector.

What is profiling in Javascript?

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.

How do I profile my website performance?

To access the Performance tab, navigate to the website you want to profile, then open Chrome DevTools by right-clicking and selecting Inspect. Select the Performance tab inside Chrome DevTools. The easiest way to capture a performance profile is by clicking the Start profiling and reload page icon.


1 Answers

When I used to profile my JavaScript code I used Chrome's profiler; the JavaScript Console in the developer view gives it, and it pretty much worked for me. Have you ever tried it?

like image 171
Masiar Avatar answered Oct 06 '22 00:10

Masiar