Im testing this code:
string teststring = ""; int i = 0; while ( i < 100000000 ) { i++; } The execution time is: 0.359 s.
Then I try to do the exact same test again, but this time Ive added one extra line within the loop:
string teststring = ""; int i = 0; while ( i < 100000000 ) { i++; teststring += "something random"; } The execution time is 4 s.
Its one extra line, should it really take that much longer? Can I do something different to improve this?
int i = 0; while ( i < 100000000 ) {i++;}likely gets optimized toint i = 100000000;or something similar.