Generic Object vs Class (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script>
  function SomeClass(a, b) {
   this.a = a;
   this.b = b;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Class
var firstClass = new SomeClass(0, 0);
var lastClass = firstClass;

for (var i = 0; i < 1000; i++) {
 lastClass = lastClass.next = new SomeClass(i, 10);
}

var test = firstClass;
while (test != null) {
 var c = test.a + test.b;
 test = test.next;
}
ready
Generic
var firstGeneric = {
 a: 0,
 b: 0
};
var lastGeneric = firstGeneric;

for (var i = 0; i < 1000; i++) {
 lastGeneric = lastGeneric.next = {
  a: i,
  b: 10
 };
}

var test = firstGeneric;
while (test != null) {
 var c = test.a + test.b;
 test = test.next;
}
ready
Class w/ local reference
var c = SomeClass;
var firstClass = new c(0, 0);
var lastClass = firstClass;

for (var i = 0; i < 1000; i++) {
 lastClass = lastClass.next = new c(i, 10);
}

var test = firstClass;
while (test != null) {
 var c = test.a + test.b;
 test = test.next;
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.