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
var matrix,obj,i,j,len,index;
matrix = new Array(1000*1000*4);
len = matrix.length;
obj = {0:255,1:0,2:255,3:255};
function commonFor()
{
for (i = 0; i < lengthImgData; i+=4)
{
matrix[i] = obj[0];
matrix[i+1] = obj[1];
matrix[i+2] = obj[2];
matrix[i+3] = obj[3];
}
}
function nestedFor()
{
for(i = 0; i < 1000; i += 1)
{
for(j = 0; j < 1000; j += 1)
{
index = (j + i * 1000) * 4;
matrix[index] = obj[0];
matrix[index+1] = obj[1];
matrix[index+2] = obj[2];
matrix[index+3] = obj[3];
}
}
}
function invertedcommonFor()
{
for (i = lengthImgData; i > -1; i-=4)
{
matrix[i] = obj[0];
matrix[i+1] = obj[1];
matrix[i+2] = obj[2];
matrix[i+3] = obj[3];
}
}
function invertednestedFor()
{
for(i = 1000; i > -1 ; i -= 1)
{
for(j = 1000; j > -1; j -= 1)
{
index = (j + i * 1000) * 4;
matrix[index] = obj[0];
matrix[index+1] = obj[1];
matrix[index+2] = obj[2];
matrix[index+3] = obj[3];
}
}
}
Ready to run.
Test | Ops/sec | |
---|---|---|
common for |
| ready |
nested for |
| ready |
inverted common For |
| ready |
inverted nested For |
| ready |
You can edit these tests or add more tests to this page by appending /edit to the URL.