jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
<script>
Function.prototype.create2 = function() {
function functor() { return constructor.apply(this, args); }
var args = Array.prototype.slice.call(arguments);
functor.prototype = this.prototype;
var constructor = this;
return new functor;
};
Object.prototype.extend2 = function(extension) {
var object = Object.create(this), property;
for (property in extension)
if (Object.hasOwnProperty.call(extension, property) || typeof object[property] === "undefined")
object[property] = extension[property];
return object;
};
var bases = [];
var inherit2 = function () {
var body, parent, parent2, constructor;
if (arguments.length == 1)
body = arguments[0];
else if (arguments.length == 2) {
parent = inherit2.getPrototype(arguments[0]);
body = arguments[1];
body.prototype = parent;
bases.unshift(parent);
inherit2.getPrototype({a:1})
}
else if (arguments.length > 2) {
parent = inherit2.getPrototype(arguments[0]);
parent2 = inherit2.getPrototype(arguments[1]);
body = function () {};
body.prototype = parent;
body.prototype = body.prototype.extend2(parent2);
if (bases.length == 0) bases.push(parent);
bases.push(parent2);
Array.prototype.splice.call(arguments, 0, 2, body);
return inherit2.apply(null, arguments);
}
if (bases.length > 1) constructor = body.create2.apply(body, bases);
else constructor = (bases.length == 1) ? new body(parent) : new body;
bases = [];
constructor.init.prototype = constructor;
return constructor.init;
}
inherit2.getPrototype = function (obj) {
return (typeof obj === "object") ? obj : ((obj.prototype.init === undefined) ? new obj : obj.prototype);
}
</script>
<script>
var inherit = (function() {
"use strict";
var pt = "prototype", bases = [], body, parent, parent2, constructor, args, getprototype;
Function.prototype.create = function() {
function functor() { return constructor.apply(this, args); }
var args = Array[pt].slice.call(arguments);
functor[pt] = this[pt];
var constructor = this;
return new functor;
};
/*Object.prototype.extend = function() {
var that = (typeof this === "object") ? this : this[pt], element, property;
for (element in arguments)
if (arguments[element] !== that.extend)
for (property in arguments[element])
if (typeof that[property] === "undefined")
that[property] = arguments[element][property];
return this;
};*/
Object.prototype.extend = function(extension) {
var property, that = (typeof this === "object") ? this : this[pt];
for (property in extension)
if (typeof that[property] === "undefined") //With this line inherit is from right to left
that[property] = extension[property];
return that;
};
getprototype = function(obj) {
return (typeof obj === "object") ? obj : ((typeof obj[pt].init === "undefined") ? new obj : obj[pt]);
};
return function() {
args = arguments;
if (args.length == 1)
body = args[0];
else if (args.length == 2) {
parent = getprototype(args[0]);
body = args[1];
body[pt] = parent;
bases.unshift(parent);
}
else if (args.length > 2) {
parent = getprototype(args[0]);
parent2 = getprototype(args[1]);
body = function() {};
body[pt] = parent;
body[pt].extend(parent2);
if (bases.length == 0) bases.push(parent);
bases.push(parent2);
Array[pt].splice.call(args, 0, 2, body);
return inherit.apply(null, args);
}
if (bases.length > 1) constructor = body.create.apply(body, bases);
else constructor = (bases.length == 1) ? new body(parent) : new body;
bases = [];
constructor.init[pt] = constructor;
return constructor.init;
};
}());
</script>
<script>
var inherit3 = (function() {
"use strict";
var pt = "prototype", bases = [], body, parent, parent2, constructor, args, getprototype;
Function.prototype.create3 = function() {
function functor() { return constructor.apply(this, args); }
var args = Array[pt].slice.call(arguments);
functor[pt] = this[pt];
var constructor = this;
return new functor;
};
Object.prototype.extend3 = function(extension) {
var property, that = (typeof this === "object") ? this : this[pt];
for (property in extension)
if (typeof that[property] === "undefined") //With this line inherit is from right to left
that[property] = extension[property];
return that;
};
getprototype = function(obj) {
return (typeof obj === "object") ? obj : ((typeof obj[pt].init === "undefined") ? new obj : obj[pt]);
};
return function() {
bases = [];
args = arguments;
body = Array[pt].pop.call(args);
if (args.length > 0) {
parent = getprototype(Array[pt].shift.call(args));
bases.push(parent);
if (args.length == 0) {
body[pt] = parent;
}
else {
//console.log(1, parent)
var bodytemp = function(){};
bodytemp[pt] = parent;
for (var i in args) {
var newinherit = getprototype(args[i]);
if (i !== "extend") {
bodytemp[pt].extend3(newinherit);
bases.push(newinherit);
}
}
//console.log(2, parent)
body[pt] = bodytemp.prototype;
}
}
if (bases.length > 1) constructor = body.create3.apply(body, bases);
else constructor = (bases.length == 1) ? new body(parent) : new body;
constructor.init[pt] = constructor;
return constructor.init;
};
}());
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
recursive old |
| ready |
recursive |
| ready |
normal |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.