Just sharing some of my inconsequential lunch conversations with you... RSS  

Wednesday, January 16, 2008

Some performance tests

I was testing some code to help me architect a solution when I decided to do some (unfair) benchmarking over LINQ. Here's the classic code:

const int DIM0 = 6600;
const int DIM1 = 36;
const int DIM2 = 30;
const int DIM3 = 8;
...
for (int i = 0; i < DIM0; i++)
{
for (int j = 0; j < DIM1; j++)
{
for (int k = 0; k < DIM2; k++)
{
for (int l = 0; l < DIM3; l++)
{
sumOf += myMatrix[i, j, k, l];
}
}
}
}

On an old Dual Core (well, on one of the cores, actually, not using Parallel Extensions for now), it takes only 1 second. Quite impressive. Now I tried to query it using LINQ:

var query = (
from p in myHugeArray.Cast<System.Int32>()
select p
).Sum();

52 seconds. Ooops. Maybe I should check what this Cast is doing and post it back here.


[update]

Just to make it clearer: this is not a LINQ problem, just some trivia.

No comments:

Development Catharsis :: Copyright 2006 Mário Romano