scope lookup, cached or not

JavaScript performance comparison

Test case created by Kyle Simpson

Info

Testing/profiling the code patterns from the Script Junkie article "(pre)Maturely Optimize Your JavaScript"

http://msdn.microsoft.com/en-us/scriptjunkie/gg622887.aspx

Snippet comparison #4

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
full scope lookup
function foo() {
 function bar() {
  function baz() {
   var res = "",
       _fun = fun;
   for (var i = 0; i < 1000; i++) {
    res += fun[i % fun.length]; // not using the cached scope lookup
   }
  }
  baz();
 }
 bar();
}

var fun = "weee!";
foo();
pending…
cached scope lookup
function foo() {
 function bar() {
  function baz() {
   var res = "",
       _fun = fun;
   for (var i = 0; i < 1000; i++) {
    res += _fun[i % _fun.length]; // using the cached scope lookup
   }
  }
  baz();
 }
 bar();
}

var fun = "weee!";
foo();
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment