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
Post a Comment