Roy wrote:
I do have a List<byte[]with one million of byte[] entries (each of tem has
3 values) to convert. It takes 1 - 2 seconds to convert. And it is too slow
for my case. What is the native code to convert it with faster performance? I
don't mind how ugly the code looks like as long as the performance is best in
my case.
On my PC it takes about 0.043 seconds to convert each byte[3] to long
in a list with one million elements.
Actually I had to test with ten million elements and divide by 10,
because I could not really measure with so small data as one
million elements.
Your 1-2 seconds must be spend on something else.
I think you need to analyze the app again.
List<byte[]is not suitable for native code I think.
But because there are just 3 bytes you may be able to
do it faster that BitConverter that has to handle all
8 bytes.
The 0.043 seconds are with:
private static long Cvt1(byte[] b)
{
byte[] tmp = new byte[8];
tmp[0] = b[0];
tmp[1] = b[1];
tmp[2] = b[2];
return BitConverter.ToInt64(tmp, 0);
}
but using:
private static long Cvt2(byte[] b)
{
return (b[2] << 16) | (b[1] << 8) | b[0];
}
then I can get it down to 0.006 seconds.
But if it is probably not relevant. If your existing code takes 1.000
seconds then the difference will just reduce it to 0.963 seconds - noone
will notice the difference.
Arne