估计C+的总运行时间+;通过测量一次迭代得到的函数 我已经实现了一个C++方法,它计算给定间隔中近似值与参考函数之间的最大ULP误差。近似值和参考值均作为单精度浮点值计算。该方法从区间的下限开始,迭代范围内的每个现有单精度值

估计C+的总运行时间+;通过测量一次迭代得到的函数 我已经实现了一个C++方法,它计算给定间隔中近似值与参考函数之间的最大ULP误差。近似值和参考值均作为单精度浮点值计算。该方法从区间的下限开始,迭代范围内的每个现有单精度值,c++,performance,time,runtime,cumulative-sum,C++,Performance,Time,Runtime,Cumulative Sum,由于根据选择的范围有很多现有值,因此我想估计此方法的总运行时间,并将其打印给用户 我多次尝试执行比较以计算一次迭代的运行时间。我的方法是将一次迭代的持续时间乘以该范围内存在的浮点总数。但很明显,一次迭代的执行时间不是常数,而是取决于迭代次数,因此我估计的持续时间根本不准确。。。也许可以在主循环中调整总运行时计算 我的问题是:有没有其他方法来估计这个特定情况下的总运行时间 这是我的密码: void FloatEvaluateMaxUlp(float(*testFunction)(float), f

由于根据选择的范围有很多现有值,因此我想估计此方法的总运行时间,并将其打印给用户

我多次尝试执行比较以计算一次迭代的运行时间。我的方法是将一次迭代的持续时间乘以该范围内存在的浮点总数。但很明显,一次迭代的执行时间不是常数,而是取决于迭代次数,因此我估计的持续时间根本不准确。。。也许可以在主循环中调整总运行时计算

我的问题是:有没有其他方法来估计这个特定情况下的总运行时间

这是我的密码:

void FloatEvaluateMaxUlp(float(*testFunction)(float), float(*referenceFunction)(float), float lowBound, float highBound)
{
    /*initialization*/
    float x = lowBound, output, output_ref;
    int ulp = 0;
    long long duration = 0, numberOfFloats=0;

    /*calculate number of floats between lowBound and highBound*/
    numberOfFloats = *(int*)&highBound - *(int*)&lowBound;

    /*measure execution time of 10 iterations*/
    int iterationsToEstimateTime = 1000;
    auto t1 = std::chrono::high_resolution_clock::now();
    for (int i = 0; i < iterationsToEstimateTime; i++)
    {
        printProgressInteger(i+1, iterationsToEstimateTime);
        output = testFunction(x);
        output_ref = referenceFunction(x);
        int ulp_local = FloatCompareULP(output, output_ref);
        if (abs(ulp_local) > abs(ulp))
            ulp = ulp_local;
        x= std::nextafter(x, highBound + 0.001f);
    }
    auto t2 = std::chrono::high_resolution_clock::now();
    duration = std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();
    duration /= iterationsToEstimateTime;
    x = lowBound;
    


    /*output of estimated time*/
    std::cout <<std::endl<<std::endl<< " Number of floats: " << numberOfFloats << "   Time per iteration: " << duration << "  Estimated total time: " << numberOfFloats * duration << std::endl;
    std::cout << " Starting test in range [" << lowBound << "," << highBound << "]." << std::endl;


    long long count = 0;

    /*record start time*/
    t1 = std::chrono::high_resolution_clock::now();

    
    for (count; x < highBound; count++)
    {
        printProgressInteger(count, numberOfFloats);
        output = testFunction(x);
        output_ref = referenceFunction(x);
        int ulp_local = FloatCompareULP(output, output_ref);
        if (abs(ulp_local) > abs(ulp))
            ulp = ulp_local;
        x = std::nextafter(x, highBound + 0.001f);

    }

    /*record stop time and compute duration*/
    t2 = std::chrono::high_resolution_clock::now();
    duration = std::chrono::duration_cast<std::chrono::microseconds>(t2 - t1).count();

    /*result output*/
    std::cout <<std::endl<< std::endl << std::endl << std::endl << "*********************************************************" << std::endl;
    std::cout << "                   RESULT                                " << std::endl;
    std::cout << "*********************************************************" << std::endl;
    std::cout << " Iterations: " << count << "  Total execution time: " << duration << std::endl;
    std::cout << " Max ulp: " << ulp <<std::endl;
    std::cout << "*********************************************************" << std::endl;


}
void flootevaluatemaxulp(float(*testFunction)(float),float(*referenceFunction)(float),float lowBound,float highBound)
{
/*初始化*/
浮点x=下限、输出、输出\u参考;
int-ulp=0;
长持续时间=0,numberOfFloats=0;
/*计算下限和上限之间的浮动数*/
numberofloats=*(int*)和上限-*(int*)和下限;
/*测量10次迭代的执行时间*/
int迭代估计时间=1000;
自动t1=std::chrono::高分辨率时钟::现在();
for(int i=0;iabs(ulp))
ulp=本地ulp_;
x=std::下一个之后(x,上限+0.001f);
}
自动t2=标准::时钟::高分辨率时钟::现在();
duration=std::chrono::duration_cast(t2-t1).count();
持续时间/=迭代以估计时间;
x=下限;
/*估计时间的输出*/

std::cout为了得到更好的估计,你需要更多的数据。你的一些难题或障碍是操作系统的任务切换。另一个可能是你的时钟或测量设备的分辨率。记住,今天的处理器正在纳秒范围内执行指令。如果你运行更多的迭代,你可以得到你的MEA将数据转换为更可靠的数据,如毫秒或秒。不幸的是,时钟没有跟上这种速度。另一个问题是操作系统时钟的分辨率,H/W时钟可能有更高的分辨率,但操作系统时钟可能没有。在嵌入式系统中,示波器和逻辑分析仪用于分析。代码测试点(或仪器可夹在其上的其他设备,如LED)的校准例如,代码在测量开始时断言测试点,然后在测量结束时解除断言。通常,这些工具有足够好的时间来测量一条指令。作为平均值,将进行多个测量,以消除异常值和噪声。我们将使用sampl的平均值来自仪器的异常。由于您可能没有测量仪器或测试点,您需要在时钟测量之间至少运行1E06次迭代,以获得有意义的平均值。同样,您希望从操作系统中消除异常值和噪声。在统计中,一个样本永远不够。感谢您的解释!你是对的,我既没有测量仪器也没有测试点,这是不可能的。那么我是否正确地假设你会建议将迭代估计时间设置为1e6以消除噪音等?正如统计数据所说,数据越多,平均质量越好。