Object.observe polyfill (v3)

Revision 3 of this benchmark created by Misko Hevery on


Setup

function createWatch1(last) {
      return (last.next = {
        obj: {a:1, b:2, c:3},
        lastValue: 1,
        field: 'a',
        next: null
      });
    }
    function createWatch2(last) {
      return (last.next = {
        obj0: {a:1}, lastValue0: 1, field0: 'a',
        obj1: {a:1}, lastValue1: 1, field1: 'a',
        obj2: {a:1}, lastValue2: 1, field2: 'a',
        obj3: {a:1}, lastValue3: 1, field3: 'a',
        obj4: {a:1}, lastValue4: 1, field4: 'a',
        obj5: {a:1}, lastValue5: 1, field5: 'a',
        obj6: {a:1}, lastValue6: 1, field6: 'a',
        obj7: {a:1}, lastValue7: 1, field7: 'a',
        obj8: {a:1}, lastValue8: 1, field8: 'a',
        obj9: {a:1}, lastValue9: 1, field9: 'a',
        next: null
      });
    }
    var head1 = createWatch1({});
    var current = head1;
    for(var i = 1; i < 10000; i++) {
      current = createWatch1(current);
    }
    var head2 = createWatch2({});
    var current = head2;
    for(var i = 1; i < 1000; i++) {
      current = createWatch2(current);
    }
    dirtyCheck1 = function() {
      var current = head1;
      while(current) {
        if (current.obj[current.field] !== current.lastValue) {
           throw "Should not get here";
        }
        current = current.next;
      }
    };
    dirtyCheck2 = function() {
      var c = head2;
      while(c) {
        if (c.obj0[c.field0] !== c.lastValue0) throw "X";
        if (c.obj1[c.field1] !== c.lastValue1) throw "X";
        if (c.obj2[c.field2] !== c.lastValue2) throw "X";
        if (c.obj3[c.field3] !== c.lastValue3) throw "X";
        if (c.obj4[c.field4] !== c.lastValue4) throw "X";
        if (c.obj5[c.field5] !== c.lastValue5) throw "X";
        if (c.obj6[c.field6] !== c.lastValue6) throw "X";
        if (c.obj7[c.field7] !== c.lastValue7) throw "X";
        if (c.obj8[c.field8] !== c.lastValue8) throw "X";
        if (c.obj9[c.field9] !== c.lastValue9) throw "X";
        c = c.next;
      }
    };

Test runner

Ready to run.

Testing in
TestOps/sec
dirtyCheck1
dirtyCheck1()
ready
dirtyCheck2
dirtyCheck2()
ready

Revisions

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

  • Revision 1: published by Misko Hevery on
  • Revision 2: published by Misko Hevery on
  • Revision 3: published by Misko Hevery on
  • Revision 4: published by Misko Hevery on
  • Revision 5: published by Misko Hevery on
  • Revision 6: published by Misko Hevery on
  • Revision 7: published by Misko Hevery on
  • Revision 8: published by Misko Hevery on
  • Revision 9: published by Misko Hevery on
  • Revision 10: published by Misko Hevery on
  • Revision 11: published by Misko Hevery on
  • Revision 12: published by Misko Hevery on
  • Revision 13: published by Misko Hevery on
  • Revision 14: published by Misko Hevery on