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 src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
function isArray(obj) {
if (Array.isArray) {
return Array.isArray(obj);
}
return Object.prototype.toString.call(obj) === '[object Array]';
}
function nativeEach(obj, cb) {
if (isArray(obj)) {
eachArray(obj, cb);
} else {
eachObject(obj, cb);
}
}
function eachArray(obj, cb) {
for (var i = 0, i < obj.length; i++) {
if (cb(obj[i], i, obj) === false) {
break;
}
}
}
function eachObject(obj, cb) {
for (var prop in obj) {
if (cb(obj[prop], prop, obj) === false) {
break;
}
}
}
var testArray = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }, { id: 6 }, { id: 7 }, { id: 8 }, { id: 9 }, { id: 10 }];
var testObj = { one: 1, two: 2, three: 3, four: 4, five: 5, six: 6, seven: 7, eight: 8, nine: 9, ten: 10 };
var buffer;
var testCallback = function (v, k) {
buffer = [v, k];
};
Ready to run.
Test | Ops/sec | |
---|---|---|
_.each(obj) |
| ready |
nativeEach(obj) |
| ready |
_.each(arr) |
| ready |
nativeEach(arr) |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.