self vs this

JavaScript performance comparison

Test case created and last updated

Info

Speed of accessing self instead of this

Preparation code

<script>
  function myObj() {
    this.color = "blue";
    this.shape = "rect";
    this.text = "text";
    this.corners = "round";
    this.orientation = "up";
    this.reverse = false;
    this.flat = true;
    this.type = "orb";
 
    this.exerciseSelf = function() {
      var self = this;
      var a = self.color + self.shape + self.text + self.corners + self.orientation + self.reverse + self.flat + self.type;
      return (a);
    }
 
    this.exerciseThis = function() {
      var a = this.color + this.shape + this.text + this.corners + this.orientation + this.reverse + this.flat + this.type;
      return (a);
    }
    return (this);
  }
 
  var o = new myObj();
</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
Using this
var color = o.exerciseThis();
pending…
Using self
var color = o.exerciseSelf();
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