Global Verses Local 2

JavaScript performance comparison

Revision 5 of this test case created by Josh

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var _global = 0,
        getWhatever, doSomethingGlobal, doSomethingLocal;
   
    doSomethingGlobal = function() {
      _global = 35;
      while (_global)--_global;
    }
   
    doSomethingLocal = function() {
      var _local = _global;
      _local = 35;
      while (_local)--_local;
      _global = _local;
    }
};
</script>

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Local Variable
_global = 0;
doSomethingLocal();
pending…
Global Register
_global = 0;
doSomethingGlobal();
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment