index vs push
JavaScript performance comparison
Info
See if push and index are really as far apart as is rumored (namely, Google says in their JavaScript Style Guide that, "Note that since assigning values to an array is faster than using push() you should use assignment where possible". However, I'm finding the opposite in these tests...
http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml
Preparation code
<script>
var arr = [], i = 0;
</script>
<script>
Benchmark.prototype.teardown = function() {
arr = [], i = 0;
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Index |
|
pending… |
Push |
|
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 Mike McCaughan
- Revision 2: published
- Revision 3: published
- Revision 4: published
- Revision 6: published and last updated
- Revision 7: published
- Revision 8: published
- Revision 9: published
1 comment
Doesn't even work in IE9; throws an Out of memory error. Sweet.