Original Post
Hey I got the idea from this year's GDC. Back at home I've done a little experiment, I thought I'd share it with you. Here's the code: Results on my machine (with default "Release" configuration, VC++ 2005 Express): 16 ms vs 84 ms You may want to try it with different counts of "Test" and with different data sizes within "Test" What are your thoughts
struct Test
{
Test* next;
int data[255];
};
// ------------------------------
int _tmain(int argc, _TCHAR* argv[])
{
// Allocate an array of Test and link them together
int count = 1024 * 1024;
Test* data = new Test[count];
for (int i = 0 ; i < count ; i++)
data.next = i < count - 1 ? &data[i+1] : NULL;
// Iterate data as an array
DWORD startTimeArray = timeGetTime();
Test* pCurrentArray = data;
while(pCurrentArray->next)
++pCurrentArray;
DWORD totalTimeArray = timeGetTime() - startTimeArray;
// Iterate data as a list
DWORD startTimeList = timeGetTime();
Test* pCurrentList = data;
while(pCurrentList->next)
pCurrentList = pCurrentList->next;
DWORD totalTimeList = timeGetTime() - startTimeList;
printf("Total times: %d ms Array vs. %d ms List\n", totalTimeArray, totalTimeList);
delete [] data;
return 0;
}