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
Comparing methods for looping through an array of 10000 items and do a minimal operation with the new value each time.
In this new test, array is not regenerated for each benchmarks because of destructive methods (cf. https://twitter.com/molokoloco/status/443013019548020736) You can compare .pop() / .shift() between themselves, acknowledging they also copy the array for each test...
This big broken test, for the use of only one array and some destructive methods... (all the tests after shift() or pop() run with an empty array)
Thanks you peoples of JS ;)
<script src="https://code.jquery.com/jquery-2.1.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js"></script>
// Fake callback function (with minimal action on the value)
var tmp = 0;
var process = function(value) {
tmp = value; // Hold a ref to the variable (prevent engine optim?)
};
// PowerArray test /////////////////////////
// From : https://github.com/techfort/PowerArray
function PowerArray(array) {
var load = array || [],
self = this;
load.forEach(function(el) {
self.push(el);
});
}
PowerArray.prototype = new Array();
PowerArray.prototype.forEach = function(fun) {
var i = 0,
len = this.length;
for (; i < len; i++) {
fun(this[i], i);
}
};
// INIT : Declare and fill tests Arrays /////////////////////////
var arr = [];
var arrBuf = new Float32Array() || [];
var pa = new PowerArray();
for (var i = 0; i < 10000; i++) {
arr[i] = i; // Standard Array
arrBuf[i] = i + 0.1; // Float32Array
pa[i] = i + 0.2; // "PowerArray"
}
Ready to run.
Test | Ops/sec | |
---|---|---|
for() |
| ready |
for() caching |
| ready |
for() decrement |
| ready |
for (..in) |
| ready |
while() acting like for() |
| ready |
while() reverse |
| ready |
while(..pop()) |
| ready |
while(..shift()) |
| ready |
do while() |
| ready |
forEach() |
| ready |
map() |
| ready |
$.each() |
| ready |
_.each() |
| ready |
for with Float32Array |
| ready |
forEach() with PowerArray |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.