c++ program time statistics

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.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325059604&siteId=291194637