jsPerf.app is an online JavaScript performance benchmark test runner & jsperf.com mirror. It is a complete rewrite in homage to the once excellent jsperf.com now with hopefully a more modern & maintainable codebase.
jsperf.com URLs are mirrored at the same path, e.g:
https://jsperf.com/negative-modulo/2
Can be accessed at:
https://jsperf.app/negative-modulo/2
What is the fastest loop for function call on array?
forEach
for (i in array)
for
/ while
call()
Please, feel free to add any other ideas...
The test names are the parameters within for(a;b;c)
or while(b)
statements. For instance:
i=0;i<L;i++
refers to for(var i=0; i<L; i++) ...
i--
refers to while(i--) ...
See also a similar bench: jsperf.com/for-vs-while
var values = [];
for (var i = 0; i < 100; i++)
values[i] = i+1;
//reset sum before test to guarantee same condition
var sum = 0;
function add (val) {
sum += val;
}
Ready to run.
Test | Ops/sec | |
---|---|---|
forEach |
| ready |
for in |
| ready |
no-cache |
| ready |
call |
| ready |
i=0;i<L;i++ |
| ready |
i=0;i!==L;i++ |
| ready |
i=L-1;i>=0;i-- |
| ready |
i=L-1;i>=0;--i |
| ready |
i=L-1;i!=-1;i-- |
| ready |
i=L-1;i!=-1;--i |
| ready |
i=L;i--!=0; |
| ready |
i=L;--i!=-1; |
| ready |
i=L;i-->0; |
| ready |
i=L;--i>=0; |
| ready |
i=L;i--; |
| ready |
i=L;i; |
| ready |
i--!=0 |
| ready |
i-->0 |
| ready |
i>0 |
| ready |
--i>=0 |
| ready |
--i>=0 call |
| ready |
i |
| ready |
i-- |
| ready |
i!==L |
| ready |
++i<L |
| ready |
i<L |
| ready |
;i<L; |
| ready |
i=0;i<L; |
| ready |
i=0;i<L; * 2 |
| ready |
i<L * 2 |
| ready |
i=0;m=v[i];++i |
| ready |
i=0;m=v[i];i++ |
| ready |
i=0;m=v[i++]; |
| ready |
m=v[i++] |
| ready |
(m=v[i++])!=undefined |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.