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
Purpose of this test case is to test the performance difference between using jQuery.each or using the original javascript 'for in' construct. JavaScript's 'for in' also loops through prototype properties of the object being iterated through whereas $.each doesn't.
Update: it looks like jquery 1.6.2 has brought in $.each optimisations. Either that, or recently released browsers have much faster processing for $.each.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
Array.prototype.filter_0 = function() {
var res = [];
for (var i = 0, len = this.length; i < len; i++) {
if (this[i] !== 0) {
res.push(this[i]);
}
}
return res;
};
var listeners = ["a", "b", "c"];
var x = 0;
</script>
Ready to run.
Test | Ops/sec | |
---|---|---|
for in |
| ready |
$.each |
| ready |
for in only named elems |
| ready |
for each ... in |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.