Test name | Executions per second |
---|---|
A | 2406405.2 Ops/sec |
B | 3221296.2 Ops/sec |
C | 4528368.5 Ops/sec |
D | 4542309.0 Ops/sec |
// Declaring our Animal object
var Animal = function () {
this.name = 'unknown';
this.getName = function () {
return this.name;
}
return this;
};
// Declaring our Dog object
var Dog = function () {
// A private variable here
var private = 42;
// overriding the name
this.name = "Bello";
// Implementing ".bark()"
this.bark = function () {
return 'MEOW';
}
return this;
};
// Dog extends animal
Dog.prototype = new Animal();
// Creating an instance of Dog.
var obj = new Dog();
function iterateA() {
var ret = "";
for (var prop in obj) {
if( obj.hasOwnProperty( prop ) ) {
ret += obj[prop];
}
}
return ret;
}
function iterateB() {
var ret = "";
Object.keys(obj).forEach(function (prop) {
ret += obj[prop];
});
return ret;
}
function iterateC() {
var ret = "";
for (var i = 0, keys = Object.keys(obj); i < keys.length; i++) {
ret += obj[i];
}
return ret;
}
function iterateD() {
var ret = "";
for (var keys = Object.keys(obj), len = keys.length, i = 0; i < len; i++) {
ret += obj[i];
}
return ret;
}
var tmp = iterateA();
var tmp = iterateB();
var tmp = iterateC();
var tmp = iterateD();