array-iteration
JavaScript performance comparison
Info
Loops vs. Array methods vs. libraries.
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
Benchmark.prototype.setup = function() {
var array = [1, 3, 15, 28, 1, 243, 45, 12, 34, 56, 23, 6, 34, 345345, 345, 1245, 576, 9, 902, 9930, 8, 37, 85, 12];
function isEven(number) {
return number % 2 === 0;
}
};
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Basic uncached loop |
|
pending… |
Native Array.forEach() |
|
pending… |
jQuery $.each() |
|
pending… |
Length-cached for-loop |
|
pending… |
Foreach loop (bad bad bad!) |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments