public class Program { static void Main(string[] args) => BenchmarkRunner.Run(); } [MemoryDiagnoser] public class Test1 { int N = 32000; int[] X; public Test1() { X = new int[N]; for (int i = 0; i < N; i++) X[i] = i; } [Benchmark] public void fLINQ() { int[] Y1 = X.Skip(N / 2).Take(N / 4).ToArray(); } [Benchmark] public void fFor() { int[] Y2 = new int[N / 4]; int j = 0; for (int i = N / 2; i < 3 * N / 4; i++) Y2[j++] = X[i]; } [Benchmark] public void fRange() { int[] Y3 = X[(N / 2)..(3 * N / 4)]; } [Benchmark] public void tVector() { int[] Y = new int[N / 4]; int j = 0; for (int i = N / 2; i < 3 * N / 4; i += Vector.Count) { Vector vector = new Vector(X, i); vector.CopyTo(Y, j); j += Vector.Count; } } } | Method | Mean | Error | StdDev | Gen0 | Allocated | |-------- |----------:|----------:|----------:|-------:|----------:| | fLINQ | 17.100 us | 0.1577 us | 0.1475 us | 3.8147 | 31.37 KB | | fFor | 6.202 us | 0.0650 us | 0.0608 us | 3.8147 | 31.27 KB | | fRange | 1.579 us | 0.0226 us | 0.0189 us | 3.8166 | 31.27 KB | | fVector | 2.342 us | 0.0233 us | 0.0206 us | 3.8147 | 31.27 KB |