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
Was trying to come up with some sort of syntactic sugar that comes closer to the prettiness of Array.forEach(fn) syntax but with the performance closer to native for-loop.
Clearly "forEach2" is not it, yet. It's currently terribly worse than either a for-loop or even forEach. :)
It's mainly because for-in-loop performance is terrible compared to for-loop: http://jsperf.com/for-loop-vs-for-in-loop
<script>
Array.prototype.forEach2 = function(fn, thisObj) {
var k = {};
for (var i = 0, len = this.length; i < len; i++) this.hasOwnProperty(i) && (k[i] = 0);
fn.call(thisObj, void 0, 0, this, k);
return this;
};
var arr = ['1', true, false, "", void 0, null, 2, 18.5936];
delete(arr[3]);
var arr2 = arr.slice();
for (var j = 0; j < 500; j++) {
arr2.push(Math.round(Math.random()));
}
var arr3 = arr2.slice();
for (var m = 0; m < 5000; m++) {
arr3.push(Math.round(Math.random()));
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
small array: native forEach |
| ready |
medium array: native forEach |
| ready |
big array: native forEach |
| ready |
small array: native for-loop |
| ready |
medium array: native for-loop |
| ready |
big array: native for-loop |
| ready |
small array: forEach2 + native for-loop |
| ready |
medium array: forEach2 + native for-loop |
| ready |
big array: forEach2 + native for-loop |
| ready |
small array: reverse native for-loop |
| ready |
medium array: reverse native for-loop |
| ready |
big array: reverse native for-loop |
| ready |
while |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.