cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

notooth
Journeyman III

How long it takes to execute this code?

Hi everyone,

Can anyone tell me how long it takes to execute these code?

for (i=0; i>0; i++)

{

     // Codes take time t to execute

}

for (i=0; i<2; i++)

{

     break;

     // Codes take time t to execute

}

for (i=0; i<2; i++)

{

     // Codes take time t to execute

     break;

}

0 Likes
2 Replies
himanshu_gautam
Grandmaster

First FOR loop is never entered. Compiler can optimize this out.

Second FOR Loop is entered but immediately terminated by "break" (possibly compiler will optimize this out). So this should take the same time as first case.

Third FOR Loop will take "t" to execute

0 Likes
realhet
Miniboss

If you're looking for loop overheads:

On GCN chips (HD77xx+) the overhead is small: 1..4 cycles. If the loop is the same for all the workitems in a wavefront, it can be realized in 1 cycle with the Scalar ALU.

On older VLIW chips it costs a clause switch which can take longer time. 10-40 cycles I guess.

0 Likes