As shown below, we can count the time by introducing <time.h>:
#include<iostream> #include<time.h> #include<windows.h> using namespace std; int main() { time_t start, end; double cost; time(&start); for (int i = 0; i < 1000000000; i++) { int j = 0; j++; int k = 0; k++; } time(&end); cost = difftime(end, start); cout << cost << endl; system("pause"); return 0; }
It is convenient to see the effect when optimizing the program.