mercredi 1 août 2018

C++ execution time test

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?

Aucun commentaire:

Enregistrer un commentaire