c - time taken by for loop with (2^32-1) or (2^64-1) or more is same -
i calculated time taken loop for (i=0; i<4294967295;i++)
in c language. surprising, short (80-88 ns) on node (speed 1600mhz). later, tried run 2 loop 1 above other (i.e. for(j=0; j<4294967295;j++)
for(i=0; i<4294967295;i++)
. surprisingly, time short , same (i.e., 80ns). explain me, why time low while running many i++
in loop. additionally, when run 2 or 3 loops, why time taken these many i++
same. many in advance reply!
if loop without side-effects, compiler optimizing away completely. trick compiler generating loop anyway common trick insert asm nop
inside loop (compilers don't mess hand-inserted assembly, , cost negligible).
Comments
Post a Comment