Adding items to array
JavaScript performance comparison
Info
Various of ways to add items to an array
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Native push |
|
pending… |
Native unshift |
|
pending… |
length |
|
pending… |
Cached length |
|
pending… |
Concat |
|
pending… |
alternate unshift |
|
pending… |
Seeded push 1 |
|
pending… |
Seeded push 2 |
|
pending… |
Seeded unshift 1 |
|
pending… |
Seeded unshift 1 |
|
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
- Revision 2: published
- Revision 3: published
- Revision 4: published by V1
- Revision 5: published by Kevin Decker
- Revision 6: published by Kyle Simpson and last updated
- Revision 9: published
2 comments
The
a[a.length] = iresults are counter-intuitive. You’d think accessinglengthin each iteration would be slower. I could’ve sworn I’ve done this test before and got the opposite result, withpush(i)being the fastest. Very interesting.I think that a[a.length] = can be faster in some cases because it do not lookup the push function.