Regarding code for vector and matrix operations, I wanted to know how different techniques fare against each other and wanted an opinion from anybody who can help:
Say I have this loop.
int mat[collumns*rows*3];
for(int num = 0; num < collumns*rows; num++)
{
for(int num2 = 0; num2 < 3; num2++)
{
mat[(num*3)+(num2)] = rand()%50;
}
}
Would this loop go any faster?
int mat[collumns*rows*3];
for(int num = 0; num < collumns*rows; num++)
{
mat[(num*3)+(0)] = rand()%50;
mat[(num*3)+(1)] = rand()%50;
mat[(num*3)+(2)] = rand()%50;
}
Now say that, instead of an array, I utilize a linked list to store all integers of a matrix:
LinkedList *mat;
LinkedList *loop = mat;
while(loop)
{
loop->integer = rand()%50;
loop = loop->next;
}
Would It make any difference choosing any of these methods or is the performance optimizations negligible?
Thanks in advance!