小编The*_*101的帖子

CPP速度性能测试功能

我创建了一个简单的函数来将任何小写字母 az 转换为大写,问题可能不是问题,但每次测试都返回 0。如果我添加 system("pause") 我可以看到一个新值,指示暂停的长度。

是否有更准确的方法来测试速度,或者这实际上是否正确?我想将它与其他函数进行比较,看看它的转换速度是否比标准函数更快。

char* ToUppercase(char* Input)
{
    int Len = Length(Input);
    for (int i = 0; i < Len; i++)
    {
        short keycode = static_cast<short>(Input[i]);
        if (keycode >= 97 && keycode <= 122)
            Input[i] -= 32;
    }
    return Input;
}
Run Code Online (Sandbox Code Playgroud)

我用来测试的当前计时器是(由其他人创建的)

template<typename TimeT = std::chrono::milliseconds>
struct measure
{
    template<typename F, typename ...Args>
    static typename TimeT::rep execution(F func, Args&&... args)
    {
        auto start = std::chrono::system_clock::now();
        func(std::forward<Args>(args)...);
        auto duration = std::chrono::duration_cast< TimeT>
            (std::chrono::system_clock::now() - start);
        return duration.count();
    } …
Run Code Online (Sandbox Code Playgroud)

c++ performance-testing c++11

4
推荐指数
1
解决办法
3337
查看次数

标签 统计

c++ ×1

c++11 ×1

performance-testing ×1