C/C++中计算程序运行时间

来源:互联网 发布:淘宝客服需要会什么 编辑:程序博客网 时间:2024/06/04 19:04

F1:

头文件:#include<time.h>

开始的地方:

clock_t start, finish;
    double totaltime;
    start = clock();

结束的地方:

finish = clock();
    totaltime = (double)(finish - start) / CLOCKS_PER_SEC;
    cout << "\n此程序的运行时间为" << totaltime << "秒!" << endl;

这样就OK啦

F2:

       #include <iostream>
      #include <fstream>
      using namespace std;

        std::chrono::steady_clock::time_point t1 = std::chrono::steady_clock::now();
        // Pass the image to the SLAM system
        MultiSLAM.TrackMultiColSLAM(imgs, tframe);

        std::chrono::steady_clock::time_point t2 = std::chrono::steady_clock::now();

        double ttrack = std::chrono::duration_cast<std::chrono::duration<double> >(t2 - t1).count();

原创粉丝点击