排列-条件求和(Code)

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();
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

上一篇:总结:Apache/Tomcat/JBOSS/Jetty/Nginx区别 .


下一篇:LAV Filter 源代码分析 4: LAV Video (2)