Internal vs global

JavaScript performance comparison

Test case created by Josh

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var count = 1000;
    var doSomething = function()
    {
        for(var z=0;z<1000;z++){}
    };
   
    var obj =
    {
       i:0,
       run: function()
       {
           for(this.i=0;this.i<count;this.i++)
           {
               doSomething();
           }
       }
    };
   
    var grun = function()
    {
        for(var i=0;i<count;i++)
        {
            doSomething();
        }
    }
};
</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
global
grun();
pending…
object
obj.run();
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