使用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;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章