properties init

JavaScript performance comparison

Revision 3 of this test case created by andmaz

Info

properties init

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>


<script type="text/javascript">

var Item_obj = function(data) {

  var self = this;
  self.Prop1 = data.Prop1;
  self.Prop2 = data.Prop2;
  self.Prop3 = data.Prop3;
  self.Prop4 = data.Prop4;
  self.Prop5 = data.Prop5;
  self.Prop6 = data.Prop6;
  self.Prop7 = data.Prop7;
  self.Prop8 = data.Prop8;
  self.Prop9 = data.Prop9;
  self.Prop0 = data.Prop0;
};

var Item_prop = function(p1,p2,p3,p4,p5,p6,p7,p8,p9,p0) {

  var self = this;
  self.Prop1 = p1;
  self.Prop2 = p2;
  self.Prop3 = p3;
  self.Prop1 = p4;
  self.Prop2 = p5;
  self.Prop3 = p6;
  self.Prop1 = p7;
  self.Prop2 = p8;
  self.Prop3 = p9;
  self.Prop3 = p0;
};


var Item_obj2 = function(data) {

  var self = this;
  self.Prop1 = data["Prop1"];
  self.Prop2 = data["Prop2"];
  self.Prop3 = data["Prop3"];
  self.Prop1 = data["Prop4"];
  self.Prop2 = data["Prop5"];
  self.Prop3 = data["Prop6"];
  self.Prop1 = data["Prop7"];
  self.Prop2 = data["Prop8"];
  self.Prop3 = data["Prop9"];
  self.Prop1 = data["Prop0"];
};


function TestModel_1() {

        var self = this;
        self.items = [];
        self.update = function () {
                for (var i = 0; i < 1000; i++) {
                        self.items.push(new Item_obj({ Prop1: "" + i, Prop2: "" + i, Prop3: "" + i, Prop4: "" + i, Prop5: "" + i, Prop6: "" + i, Prop7: "" + i, Prop8: "" + i, Prop9: "" + i, Prop0: "" + i }));
                }
        };     
};


function TestModel_2() {

        var self = this;
        self.items = [];
        self.update = function () {
                for (var i = 0; i < 1000; i++) {
                        self.items.push(new Item_prop("" + i, "" + i, "" + i, "" + i, "" + i, "" + i, "" + i, "" + i, "" + i, "" + i));
                }
        };
};


function TestModel_3() {

        var self = this;
        self.items = [];
        self.update = function () {
                for (var i = 0; i < 1000; i++) {
                        self.items.push(new Item_obj2({ Prop1: "" + i, Prop2: "" + i, Prop3: "" + i, Prop4: "" + i, Prop5: "" + i, Prop6: "" + i, Prop7: "" + i, Prop8: "" + i, Prop9: "" + i, Prop0: "" + i }));
                }
        };
};

</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
simple obj
var mod = new TestModel_1();
mod.update();
pending…
simple prop
var mod = new TestModel_2();
mod.update();
pending…
other obj
var mod = new TestModel_3();
mod.update();
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