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
I want to know if decrementing a for-loop is really faster than incrementing it.
Array.prototype.loopBackward = function(searchString) {
var me = this,
numItems = this.length,
i, returnArray = [];
for (i = numItems - 1; i >= 0; i--) {
returnArray.push(me[i]);
}
return returnArray;
}
Array.prototype.loopForward = function(searchString) {
var me = this,
numItems = this.length,
i, returnArray = [];
for (i = 0; i <= numItems - 1; i++) {
returnArray.push(me[i]);
}
return returnArray;
}
var states = ["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Dakota", "North Carolina", "Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"];
var states = [];
Ready to run.
Test | Ops/sec | |
---|---|---|
For-Loop Decremented |
| ready |
For-Loop Incremented |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.