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;
};
</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… |
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
1 comment
updated for loops to read values from array instead of index value.