使用clock函數查看某個函數的執行時間

添加頭文件:#include<time>

定義時間變量:clock_t  start,end;

記錄開始時間:start = clock();

記錄結束時間:end =clock();

計算運行時間:double seconds1=(double)(end - start)/CLOCKS_PER_SEC;

#include <iostream>
#include "math.h"
#include <armadillo>
#include <time.h>
#include "6aix_robot.h"

using namespace std;

 int main()
{

        clock_t start1,end1,start2,end2;
        int i,j;
        C6AxisData MZ204;

        start1 = clock();           /*記錄起始時間*/
        MZ204.Cal_pos_by_theta();
        end1 =clock();
        double seconds1=(double)(end1 - start1)/CLOCKS_PER_SEC;
        cout<<"time1:"<<seconds1<<endl;
         
        return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章