Global - Case 3

JavaScript performance comparison

Revision 2 of this test case created by Cong Liu

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var obj = {};
    var v = obj.v = self.v = 0;
   
    function test1() {
      self.v += 1;
    }
   
    function test2() {
      obj.v += 1;
    }
   
    function test3() {
      v += 1;
    }
   
    function bench(func) {
      for (var i = 0; i < 50000; i++) func();
    }
};

Benchmark.prototype.teardown = function() {
    v = obj.v = self.v = 0;
};
</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
self.v+=1
bench(test1)
pending…
obj.v += 1
bench(test2)
pending…
v += 1 (Closure)
bench(test3)
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