using System; using System.Collections.Generic; using System.Linq; using System.Diagnostics; namespace CSharpTest { class MainClass { private static void TestListCount(int n) { for (int i = 1; i <= n; i *= 2) { var l = new List(Enumerable.Range(0, i)); var scaledBy2 = l.Select (x => x * 2); int actualCount = 0; var sw = new Stopwatch(); sw.Reset(); sw.Start(); actualCount = scaledBy2.Count(); sw.Stop(); Console.WriteLine("{0} for N = {1} -> {2}, List.Select(..).Count()", sw.Elapsed, i, actualCount); } } private static void TestArrayCount(int n) { for (int i = 1; i <= n; i *= 2) { var arr = Enumerable.Range(0, i).ToArray(); var scaledBy2 = arr.Select (x => x * 2); int actualCount = 0; var sw = new Stopwatch(); sw.Reset(); sw.Start(); actualCount = scaledBy2.Count(); sw.Stop(); Console.WriteLine("{0} for N = {1} -> {2}, Array.Select(..).Count()", sw.Elapsed, i, actualCount); } } public static void Main (string[] args) { const int n = 16777216; TestListCount(n); TestArrayCount(n); } } }