Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Number of Javascript lines executed during page load

I have an use case where I need to get the total number of Javascript lines executed when my web page is loading.

The problem I am facing is that the browser throws an alert when a certain number of JS execution exceed ( 5 million I think in case of IE ) and the page gets hanged.

I used the profiler available in IE Developers tool bar,but it gives me the total number of JS functions called but not the total number/count of lines executed.

Any help is appreciated.

Thanks

like image 304
sathishvisa Avatar asked Nov 13 '12 16:11

sathishvisa


2 Answers

This may help:

http://www-archive.mozilla.org/performance/jsprofiler.html

The first line specifies the js file from which times were gathered. Each line below that is of the format: [A, B] C {D-E} F {G, H, I}

D -> Base line number of the function in the JS file
E -> Extent (last) line number of the function in the JS file

like image 154
nullable Avatar answered Nov 16 '22 22:11

nullable


First of all, you should really redesign your code; 5 million statements without handing control back to the browser is by all means a lot of code, imagine how mobile browsers will struggle with it.

One way to find out how many statements are executed is by instrumenting your code, adding one statement for each statement in your code to count the number of times it was executed, effectively doubling up the number of statements in your code.

There are also code coverage tools that can run inside the browser without having to instrument your code at all; Googling for "javascript code coverage" gives a fair amount of browser extensions that you could use, such as hrtimer.

like image 1
Ja͢ck Avatar answered Nov 16 '22 21:11

Ja͢ck