looping
JavaScript performance comparison
Info
I have an array, I want a new array where I do something to it, how do I do it fastest.
Preparation code
<script src="//raw.github.com/documentcloud/underscore/master/underscore-min.js">
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
Benchmark.prototype.setup = function() {
var _len = 10000;
var a = new Array(_len);
while (_len--) {
a[_len] = _len;
}
var f = function(a) {
return a * a;
}
};
</script>
Preparation code output
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
while -- |
|
pending… |
do/while |
|
pending… |
while push |
|
pending… |
while++!== |
|
pending… |
while++< |
|
pending… |
for -- |
|
pending… |
for++;!== |
|
pending… |
for++;< |
|
pending… |
map |
|
pending… |
jQuery map |
|
pending… |
underscore map |
|
pending… |
forEach |
|
pending… |
while++< with no init size |
|
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 cwmma
- Revision 2: published by Martijn Faassen
- Revision 3: published
- Revision 4: published
- Revision 5: published
- Revision 6: published
- Revision 7: published
- Revision 8: published
- Revision 9: published
- Revision 10: published
- Revision 12: published
0 comments