hasOwnProperty-vs-noVerification

Benchmark created by Couto on


Preparation HTML

<script>
Klass = function (methods) {
    'use strict';
    var extend = function (what, methods) {
            var k;
            for (k in methods) {
                if (methods.hasOwnProperty(k)) { // kinda useless i guess
                    what.prototype[k] = methods[k];
                }
            }
        },
        include = function (to, from) {
            var i = from.length - 1,
                k;
            for (i; i >= 0; i -= 1) {
                for (k in from[i].prototype) {
                    if (from[i].prototype.hasOwnProperty(k)) {
                        to.prototype[k] = from[i].prototype[k];
                    }
                }
            }
        };



    function klass() {}

    if (methods.Super) {
        klass.prototype = new methods.Super();
        extend(klass, methods, methods.Super);
    } else {
        klass.prototype = methods;
    }
    klass.prototype.constructor = klass;

    if (methods.Implements) {
        include(klass, methods.Implements);
    }

    return klass;
};

Klass2 = function (methods) {
    'use strict';
    var extend = function (what, methods) {
            var k;
            for (k in methods) {

                    what.prototype[k] = methods[k];

            }
        },
        include = function (to, from) {
            var i = from.length - 1,
                k;
            for (i; i >= 0; i -= 1) {
                for (k in from[i].prototype) {
                        to.prototype[k] = from[i].prototype[k];
                }
            }
        };



    function klass() {}

    if (methods.Super) {
        klass.prototype = new methods.Super();
        extend(klass, methods, methods.Super);
    } else {
        klass.prototype = methods;
    }
    klass.prototype.constructor = klass;

    if (methods.Implements) {
        include(klass, methods.Implements);
    }

    return klass;
};


</script>

Test runner

Ready to run.

Testing in
TestOps/sec
hasOwnProperty
var Lol = Klass({
  init: function() {
    return "Hello World";
  },
  method: function(who) {
    return "Hello" + who;
  }
});

var lol = new Lol();
ready
no Verfication
var Lol = Klass2({
  init: function() {
    return "Hello World";
  },
  method: function(who) {
    return "Hello" + who;
  }
});

var lol = new Lol();
ready

Revisions

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

  • Revision 1: published by Couto on