C++统计函数调用时间

#include<iostream>
#include<assert.h>
#include<vector>
#include<chrono>

int main()
{
   int iter = 10000;
    std::vector<double> coeffs = { 4, 2, -2, 5, 0, 15};
    std::vector<double> valuesToEvaluate = {0, 2, -4, 8, 15, 1.25, 512 ,-5.3 
    ,12.215, 153, 23, -11};
    auto start = std::chrono::high_resolution_clock::now();

    do{
    std::vector<double> results = Polyval(coeffs, valuesToEvaluate);
    }
    while(iter-->0);

    auto end = std::chrono::high_resolution_clock::now();
    long duration = std::chrono::duration_cast<std::chrono::microseconds>(end - 
    start).count();

    std::cout << duration << std::endl;  
}
posted @ 2022-06-16 10:29  Truman001  阅读(148)  评论(0编辑  收藏  举报