static void Main(string[] args) { // Generate data int arraySize; int[] data; Random rnd; arraySize = 32768; data = new int[arraySize]; rnd = new Random(0); for (int c = 0; c < arraySize; ++c) data[c] = rnd.Next(256); // Test long sum = 0; CodeTimer.Time("unsorted array", 100000, () => { for (int c = 0; c < arraySize; ++c) { if (data[c] >= 128) sum += data[c]; } }); Array.Sort(data); sum = 0; CodeTimer.Time("sorted array", 100000, () => { for (int c = 0; c < arraySize; ++c) { if (data[c] >= 128) sum += data[c]; } }); Console.ReadKey(); }
原文:http://www.cnblogs.com/zhaoschuan/p/4356376.html