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
Serious Test for common method for looping an array:
Array.forEach
.each
from various frameworks: jQuery, Ext, underscore (original & fallback version)Array.prototype.each
Array size: 1000 (array size for testing the true processing power, unusual but possible)
<script src="//ajax.googleapis.com/ajax/libs/prototype/1/prototype.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script src="http://cdn.sencha.io/ext-4.1.0-gpl/ext-all.js">
</script>
<script src="https://raw.github.com/documentcloud/underscore/master/underscore.js">
</script>
<script>
$.fn.forEach = Array.prototype.forEach;
var extArrayEach = Ext.Array.each;
Array.prototype.each = function(func){
var array = this,
i = 0,
l = array.length;
while(i < l) func(array[i], i, array), i++;
return array
};
var breaker = {};
_.forEach = function(obj, iterator, context) {
if (obj == null) return;
if (obj.length === +obj.length) {
for (var i = 0, l = obj.length; i < l; i++) {
if (iterator.call(context, obj[i], i, obj) === breaker) return;
}
} else {
for (var key in obj) {
if (_.has(obj, key)) {
if (iterator.call(context, obj[key], key, obj) === breaker) return;
}
}
}
};
//a static array.
var a = [];
for (var i = 0, len = 1000; i < len; i++) {
a[i] = i;
}
function makeid()
{
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for( var i=0; i < 5; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
var b = {};
for (var i = 0, len = 1000; i < len; i++) {
b[makeid()] = i;
}
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
jQuery.each |
| ready |
for loop |
| ready |
forEach |
| ready |
Ext.Array.each |
| ready |
Array.prototype.each |
| ready |
_.each |
| ready |
_.each (fallback) |
| ready |
jquery each obj |
| ready |
for obj |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.