I need to copy FAST a portion of an array into another, replacing it's old values.
- No range checkings needed.
- Number of items to copy: 16384
- The array only contains integers
benchmark code: http://codebase.es/test/copytest.htm
This is my approach:
var i = 0x4000>>5; // loops count
var j = 0x4000; // write start index
var k = 0x8000; // read start index
while (i--) { // loop unrolling
dst[j++]=src[k++]; dst[j++]=src[k++];
dst[j++]=src[k++]; dst[j++]=src[k++];
dst[j++]=src[k++]; dst[j++]=src[k++];
dst[j++]=src[k++]; dst[j++]=src[k++];
//8
dst[j++]=src[k++]; dst[j++]=src[k++];
dst[j++]=src[k++]; dst[j++]=src[k++];
dst[j++]=src[k++]; dst[j++]=src[k++];
dst[j++]=src[k++]; dst[j++]=src[k++];
//16
dst[j++]=src[k++]; dst[j++]=src[k++];
dst[j++]=src[k++]; dst[j++]=src[k++];
dst[j++]=src[k++]; dst[j++]=src[k++];
dst[j++]=src[k++]; dst[j++]=src[k++];
//24
dst[j++]=src[k++]; dst[j++]=src[k++];
dst[j++]=src[k++]; dst[j++]=src[k++];
dst[j++]=src[k++]; dst[j++]=src[k++];
dst[j++]=src[k++]; dst[j++]=src[k++];
//32
}
can this be done faster?