This question is in reference to this question of mine Time Difference between the execution of the C++ program with and without print statement.
Look at these codes:
1) Without print
statement:
#include <iostream>
#include <ctime>
#include <boost/multiprecision/cpp_int.hpp>
using big_int = boost:: multiprecision:: cpp_int;
using namespace std;
clock_t start = clock();
int main() {
for(big_int i = 0; i < 10000000; ++i) {
}
double elapsedTime = static_cast<double>(clock() - start) / CLOCKS_PER_SEC;
cout << endl << "Time is " << elapsedTime << " Seconds";
return 0;
}
Execution Time:
Time is 0.370125 Seconds
2) With print
statement
#include <iostream>
#include <ctime>
#include <boost/multiprecision/cpp_int.hpp>
using big_int = boost:: multiprecision:: cpp_int;
using namespace std;
clock_t start = clock();
int main() {
for(big_int i = 0; i < 10000000; ++i) {
cout << i << endl;
}
double elapsedTime = static_cast<double>(clock() - start) / CLOCKS_PER_SEC;
cout << endl << "Time is " << elapsedTime << " Seconds";
return 0;
}
Execution Time:
Time is 26.8947 Seconds
I want to know that like these two codes why there is not a significant difference in the execution time of the codes mentioned in this question.