Fastest way of transversing an array
JavaScript performance comparison
Info
This is meant to test which way is the fastest to transverse an array, specially when performance is important
Preparation code
<script>
Benchmark.prototype.setup = function() {
var thingy = [1, "test", 44, true, false, "tester", 212313213, "testestetestetest stest ,...!", 2, true, "more", "extra", "stuff", "to", "make", "it", "more", "challenging"];
var thingy2;
var testArray = [];
for (i = 0; i < 100000; i++) {
testArray.push(i);
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
For In |
|
pending… |
For Loop |
|
pending… |
For Loop (Length Cached) |
|
pending… |
For Loop (Length Cached in for) |
|
pending… |
Backwards for loop |
|
pending… |
Backwards for loop (less commands) |
|
pending… |
large array for. |
|
pending… |
large array for with cached length. |
|
pending… |
large array for in test. |
|
pending… |
Compare results of other browsers
Revisions
You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:
- Revision 1: published by Vaughn
- Revision 2: published
- Revision 3: published
- Revision 4: published
- Revision 5: published
0 comments