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
A comparison of the type checking in http://techblog.badoo.com/blog/2013/11/01/type-checking-in-javascript/ , manual type checking, and having no type checking.
<script>
var arr = [];
for(var i = 0; i <= 30000; i++) arr.push(i);
(function (root) {
var type = function (o) {
// handle null in old IE
if (o === null) {
return 'null';
}
// handle DOM elements
if (o && (o.nodeType === 1 || o.nodeType === 9)) {
return 'element';
}
var s = Object.prototype.toString.call(o);
var type = s.match(/\[object (.*?)\]/)[1].toLowerCase();
// handle NaN and Infinity
if (type === 'number') {
if (isNaN(o)) {
return 'nan';
}
if (!isFinite(o)) {
return 'infinity';
}
}
return type;
};
var types = [
'Null',
'Undefined',
'Object',
'Array',
'String',
'Number',
'Boolean',
'Function',
'RegExp',
'Element',
'NaN',
'Infinite'
];
var generateMethod = function (t) {
type['is' + t] = function (o) {
return type(o) === t.toLowerCase();
};
};
for (var i = 0; i < types.length; i++) {
generateMethod(types[i]);
}
if (typeof exports === "object" && exports) {
exports = type;
}
else if (typeof define === "function" && define.amd) {
define(type);
}
else {
root.type = type;
}
})(this);
</script>
var result = [];
Ready to run.
Test | Ops/sec | |
---|---|---|
type function check |
| ready |
typeof manual check |
| ready |
no type check |
| ready |
type function filter |
| ready |
typeof manual filter |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.