I am currently working on an application that is responsible for calculating random permutations of a jagged array.
Currently the bulk of the time in the applicati
Either of these should work for you. They both run in about the same amount of time and are both much faster than your method.
// 100 passes on a int[1000][1000] set size
// 701% faster than original (14.26%)
static int[][] CopyArrayLinq(int[][] source)
{
return source.Select(s => s.ToArray()).ToArray();
}
// 752% faster than original (13.38%)
static int[][] CopyArrayBuiltIn(int[][] source)
{
var len = source.Length;
var dest = new int[len][];
for (var x = 0; x < len; x++)
{
var inner = source[x];
var ilen = inner.Length;
var newer = new int[ilen];
Array.Copy(inner, newer, ilen);
dest[x] = newer;
}
return dest;
}