I learned about loop unrolling a long time ago and got the sudden inspiration this morning to try it in action. So i whipped together this little program.
String s=""; for (int i = 0; i < 10000 ; i++){ s = s + i; }
I compared the runtime to this guy here.
for (int i = 0; i < 10000 ; i = i + 10){ s = s + i; s = s + (i+1); s = s + (i+2); s = s + (i+3); s = s + (i+4); s = s + (i+5); s = s + (i+6); s = s + (i+7); s = s + (i+8); s = s + (i+9); }
I consistently got a longer run time on the second loop. Is this because the compiler simply did a better job of unrolling the loop than I did or I am missing something much bigger?
Thanks HelloWorld for fixing code blocks. Was just reading about that =)