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>
if (!Array.prototype.first) {
/**
* Finds the first item in an array that satisfies a function, or the first item overall if no function is supplied.
* @param {function(*):Boolean} [fn] The function to use to find an item.
* @returns {*} An item from the array, or false if the array is empty or no matching item is found.
*/
Object.defineProperty(Array.prototype, "first", {
value: function (/* fn */) {
if (arguments.length === 0) {
return this.length > 0 ? this[0] : false;
}
const fn = arguments[0];
if (typeof fn !== "function") {
throw new TypeError();
}
const t = Object(this);
const len = t.length >>> 0;
const thisArg = arguments.length >= 2 ? arguments[1] : void 0;
for (let i = 0; i < len; i++) {
if (i in t) {
const res = fn.call(thisArg, t[i], i, t);
if (res) {
return t[i];
}
}
}
return false;
}
});
}
</script>
var arr = [{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }, { id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 },{ id: 1 }];
Ready to run.
Test | Ops/sec | |
---|---|---|
First |
| ready |
Find |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.