javascript - testing js variable declaration speed -


i want speed tests on basic stuff variable declaration.

now have function executes x times have more significant time difference.

http://jsfiddle.net/etbsv/ (you need open console & takes few seconds execute)

this code:

var doit = 10000000,     = 0,     i2 = 0;  //testing var comma console.time('timer');       function test(){     var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z; }; while (i<=doit){    test();          i++; }; console.timeend('timer');  //testing individual var declarations  console.time('timer2'); function test2(){      var a; var b; var c; var d; var e; var f; var g; var h; var i; var j; var k; var l; var m; var n; var o; var p; var q; var r; var s; var t; var u; var v; var w; var x; var y; var z;  };  while (i2<=doit){      test();      i2++;  };  console.timeend('timer2'); 

now have 2 questions:

  1. is accurate way of testing speed of variable declarations?
  2. how test more cycles without having firefox crash? if set doit 1000000000 example, firefox want stop script.
  3. why results (of script , in jspref) different each time? sometime individual variable declaration faster grouped :/

edit made js pref testcase: http://jsperf.com/testing-js-variable-declaration-speed nice if of different browsers , configuration participate. im still interested know if way of testing accurate.

is accurate way of testing speed of variable declarations?

it's enough rough idea, it's not perfect. things, relies on cpu. if cpu spikes during testing due application, such virus scanner, or action browser, such phishing check, javascript execution can slowed. when cpu idle, it's not exact science , have run many times average.

how test more cycles without having firefox crash? if set doit 1000000000 example, firefox want stop script.

firefox limits javascript execution maximum of 10 seconds. i'm not sure if there's work around.

why results (of script , in jspref) different each time? sometime individual variable declaration faster grouped :/

because there's no real difference between two. variable declarations "hoisted", , it's done @ parse-time instead of run-time optimization, internal representation of functions after have been parsed identical. difference subtle factors affecting time takes initialize undefined variables , execute otherwise empty functions.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -