Re-write for loop to make it run quicker??

hello, is there anyway to re-write this loop to make it run quicker??

// All variables are integers

for (j = 0; j < num_c_symbols; j++)
{
LT_c_symbols[j*(SymSize+3)]=block_Id;
LT_c_symbols[j*(SymSize+3)+1]=j/255; LT_c_symbols[j*(SymSize+3)+2]=j%255;
for(int ss=3;ss<SymSize+3;ss++)
{
LT_c_symbols[j*(SymSize+3)+ss] = 0;
}
for ( i = 0; i < LT_c_node[j].degree; i++)
for(int ss=3;ss<SymSize+3;ss++)
{
LT_c_symbols[j*(SymSize+3)+ss] = LT_c_symbols[j*(SymSize+3)+ss] ^ LT_s_symbols[(LT_c_node[j].edge[i])*(SymSize+3)+ss];
}
}
coded_length=num_c_symbols;

thanks,
closed account (zb0S216C)
Do you mean performance optimization, or improve it logically? You can't improve the speed at which a loops runs as that falls down to the CPU. Improving it logically, yes. However, you need to add code tags to make you code readable.

Wazzak
Compute "j*(SymSize+3)" just once at the beginning of the loop, rather than calculating it again all over the place.

Are you sure the division and modulo by 255 is correct? Dividing by 256 to break down a word into individual bytes seems much more likely. In that case, you could change the divisions with bitwise operations for a marginal speedup.

The loop performs too few operations to suggest any further improvements.
Last edited on
Thanks Guys! =)
Replace i++ and j++ with ++i and ++j. Maybe replace the first nested loop with a memset. Perhaps use pointer arithmetic instead of repeated operator[].
Topic archived. No new replies allowed.