This will work faster, for small data that Parallel.For(0, count, (j) =>
should not do Parallel.For(0, count, (j) =>
, in fact it works much slower for very small data, so I commented on this section.
double* dp0; float* fp0; fixed (double* dp1 = dbl) { dp0 = dp1; float[] newFlt = new float[count]; fixed (float* fp1 = newFlt) { fp0 = fp1; for (int i = 0; i < numCh; i++) {
This works faster because double access to double arrays [,]
really taxed in .NET due to checking the boundaries of the array. newFlt.Clone()
simply means that we do not newFlt.Clone()
or untie new pointers all the time (since there is little overhead at the same time)
You will need to run it with the unsafe
tag and compile with /UNSAFE
But in fact, you should work with data closer to 5000 x 5000 not 5 x 2, if something takes less than 1000 ms, you need to either add more cycles or increase data, because at this level a slight surge in processor activity can add a lot of noise in profiling.
source share