javascript - Caculating function running time -


i want calculate average running time of function in javascript this:

time = 0;  while(1000) {   time1 = performance.now();   function();   time2 = performance.now();   time += (time2-time1); } 

the problem first loop time interval 60ms , following loop interval zero. changed code to:

time1 = performance.now();  while(1000000) {          function(); }  time2 = performance.now(); time = (time2-time1); 

the running time 4 seconds.

i guess maybe because of automatic optimisation.

if case, there approaches close optimisation?

you've caused browser hand off code jit compiler. first run through interpreter (slow). hot code gets put through jit , resulting native (fast) code used.

this automatic , out of hands control. can disable firefox jit compiler using 'with' in script.

with({}) {} 

add top of script , jit disabled script.


Comments

Popular posts from this blog

c++11 - Intel compiler and "cannot have an in-class initializer" when using constexpr -

rest - Spring boot: Request method 'PUT' not supported -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -