jani-iterating arrays

JavaScript performance comparison

Test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/mootools/1.3/mootools-yui-compressed.js"></script>
 
<script>
Benchmark.prototype.setup = function() {
    var src = [];
    for (var i = 0; i < 5000; i++) {
    src.push(i);
    }
   
    var cv,ci;
};
</script>

Preparation code output

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
mootools each
src.each(function(value,index) {
cv = value;
ci = index;
});
pending…
mootools each without index
src.each(function(value) {
cv = value;
});
pending…
for easy
for(var i = 0; i < src.length; i++) {
cv = src[i];
ci = i;
}
pending…
for easy without index
for(var i = 0; i < src.length; i++) {
cv = src[i];
}
pending…
for
for(var i = 0, l = src.length; i < l; i++) {
cv = src[i];
ci = i;
}
pending…
for without index
for(var i = 0, l = src.length; i < l; i++) {
cv = src[i];
}
pending…
while
var i,v;
while(v = src[i++]) {
cv = v;
ci = i;
}
pending…
while without index
var i,v;
while(v = src[i++]) {
cv = v;
}
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment