Object creation optimization

JavaScript performance comparison

Revision 2 of this test case created

Preparation code

<script>
  function createObject2(x, y, z, d, e, f) {
    this.x = x;
    this.y = y;
    this.z = z;
    this.x1 = d;
    this.y1 = e;
    this.z1 = f;
  }

  function createSimpleObject(a, b, c, d, e, f) {
    return {x:a, y:b, z:c, x1:d, y1:e, z1:f};
  }
</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, x1: 4, y1: 5, z1: 6}
for (var obj in elem) {
  elem[obj] = elem[obj] + 1;
}
pending…
function generated
var elem = createObject2(1, 2, 3, 4, 5, 6);
for (var obj in elem) {
  elem[obj] = elem[obj] + 1;
}
pending…
simple object function
var elem = createSimpleObject(1, 2, 3, 4, 5, 6);
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