this versus local variableXX

JavaScript performance comparison

Revision 4 of this test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function Item1() {
      this.test = Math.random(); //N = random value;
    }
   
    Item1.prototype.f = function() {
      var a = this.test * 10;
      var b = this.test * 20;
      var c = this.test * 30;
    }
   
    function Item2() {
      this.test = Math.random(); //N = random value;
    }
   
    Item2.prototype.f = function() {
      var test = this.test;
      var a = test * 10;
      var b = test * 20;
      var c = test * 30;
    }
   
    var Titems1 = [];
    for (var i = 0; i < 3000; ++i)
    {
    Titems1.push(new Item1());
    }
   
    var Litems1 = [];
    for (var i = 0; i < 3000; ++i)
    {
    Litems1.push(new Item2());
    }
};
</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
This
for (var i = 0; i < 3000; i++) {
  Titems1[i].f();
}
pending…
Local
for (var i = 0; i < 3000; i++) {
  Litems1[i].f();
}
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