小编Psy*_*261的帖子

加速 if-else 梯形图 C++

我有一段代码对执行速度的要求高于其他任何东西。通过使用high_resolution_clock()from,std::chrono我发现这个 switch() 到 if-else() 梯子占用了我 70% 以上的执行时间。有什么办法可以加快这个速度吗?

我在编译过程中使用了gcc优化-O3

我研究了一个类似的问题:If elseladder optimization但我不能使用 return 语句,因为它会退出我不能的外循环。

switch(RPL_OPTION) {
            case 0:
                for(int k = 0; k < WINDOW_SIZE; k++) {
                    if(ans[k] >= upper_th) {
                        //Increasing flag counter
                        flag_count++;
                        //Adding the filtered value to the output vector
                        filtered_output.push_back(ans[k]);
                        flag_output.push_back(1);

                    } else if(ans[k] < lower_th) {
                        //Increasing flag counter
                        flag_count++;
                        //Adding the filtered value to the output vector
                        filtered_output.push_back(ans[k]);
                        flag_output.push_back(1);

                    } else {
                        //Adding the filtered …
Run Code Online (Sandbox Code Playgroud)

c++ optimization performance if-statement execution-time

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