WID.Core Class test

JavaScript performance comparison

Revision 3 of this test case created by Mararok

Info

testing performence of creating class with new WebInDream(https://code.google.com/p/web-in-dream/) class system

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    function Class(constructor, definition) {
      var
      ret = constructor,
          base = definition.base;
      if (!constructor) {
        throw new Error("[Class] Undefined constructor, can't create class");
      }
   
      if (definition.interfaces) {
        constructor.INTERFACES = definition.interfaces;
      }
   
      if (base) {
        constructor.SUPER = base;
        constructor.prototype = Object.create(base.prototype);
        constructor.prototype.$super = base.prototype;
   
        ret = constructor.prototype;
        ret.constructor = constructor;
   
      } else if (definition.methods) {
        constructor.prototype = definition.methods;
      } else {
        throw new Error("[Class] undefined methods can't create class");
      }
   
      if (definition.props) {
        Object.defineProperties(constructor.prototype, definition.props);
      }
   
      return ret;
    }
   
    function oldSuper() {
      this.a = 0;
    }
   
    oldSuper.prototype = {
      constructor: oldSuper,
      test: function() {
        return 1;
      }
    };
   
    function newSuper() {
      this.a = 0;
    }
    Class(newSuper, {
      methods: {
        constructor: newSuper,
        test: function() {
          return 1;
        }
      }
    });
   
    function oldChild1() {
      oldSuper.call(this);
    }
    var extend = Object.create(oldSuper.prototype);
    extend.constructor = oldChild1;
   
    extend.test = function() {
      if (oldSuper.prototype.test.call(this) !== 1) throw new Error('error');
    }
    oldChild1.prototype = extend;
   
    function newChild1() {
      this.$super.constructor();
    }
    var extend = Class(newChild1, {
      base: newSuper
    });
    extend.test = function() {
      if (this.$super.test() !== 1) throw new Error('error');
    };
};
</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
1. Old: system
function c() {}

c.prototype = {
  constructor: c,
  test: function() {}
};
pending…
2. New: system
function c() {}
Class(c, {
  methods: {
    constructor: c,
    test: function() {}
  }
});
pending…
3. Old: create subclass
function oldChild() {
  oldSuper.call(this);
}
var extend = Object.create(oldSuper.prototype);
extend.constructor = oldChild;

extend.test = function() {
  if (oldSuper.prototype.test.call(this) !== 1) throw new Error('error');
}

oldChild1.prototype = extend;
pending…
4. New: create subclass
function newChild() {
  this.$super.constructor();
}
var extend = Class(newChild, {
  base: newSuper
});
extend.test = function() {
  if (this.$super.test() !== 1) throw new Error('error');
};
pending…
5. Old: create object
var o = new oldChild1();
o.test();
pending…
6. New: create object
var o = new newChild1();
o.test();
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