Object creation optimization

JavaScript performance comparison

Test case created

Preparation code

<script>
  function createObject(x, y) {
    this.x = x;
    this.y = y;
  }

  function createObject2(x, y, z) {
    this.x = x;
    this.y = y;
    this.z = z;
  }

  function createSimpleObject(a, b, c) {
    return {x:a,y:b,z:c};
  }
</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
code inlining
var elem = { x: 1, y: 2, z: 3, }
for (var obj in elem) {
  elem[obj] = elem[obj] + 1;
}
pending…
function generated
var elem = createObject2(1, 2, 3);
for (var obj in elem) {
  elem[obj] = elem[obj] + 1;
}
pending…
simple object function
var elem = createSimpleObject(1, 2, 3);
for (var obj in elem) {
  elem[obj] = elem[obj] + 1;
}
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