Parameter lookup vs. instance variables

JavaScript performance comparison

Test case created by NIME_Test

Info

This test looks at how much quicker it is to reference parameter values as opposed to instance variables inside a method.

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var obj = {
      callback: function(a, b) {
        return a + b;
      },
      callback2: function() {
        return this.a + this.b;
      },
      a: 2,
      b: 3,
    };
};
</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
parameters
var a = obj.callback(2,3);
pending…
instance variables
var a = obj.callback2();
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