| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 493 人关注过本帖
标题:请教如何提高该段代码的执行效率
只看楼主 加入收藏
zzjjll
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-11-8
收藏
 问题点数:0 回复次数:0 
请教如何提高该段代码的执行效率
各位高手:该段代码由于需要将4个判断条件都执行才能进行赋值计算,所以执行效率偏低。
如何提高能提高执行效率。
                  for(循环)
                  {
                          if(p[0][im2]<-9990 ||
                             p[1][im2]<-9990 ||
                             p[2][im2]<-9990 ||
                             p[3][im2]<-9990)
                            ptt[im2] = -9990.0f;
                          else
                            ptt[im2]= ff[0]*p[0][im2]
                              + ff[1]*p[1][im2]
                              + ff[2]*p[2][im2]
                              + ff[3]*p[3][im2];
                   }

我做了如下改进:
                                                 if(p[0][im2]<-9990)ptt[im2] = -9990.0f;
                                             else
                                             {
                                                if(p[3][im2]<-9990)ptt[im2] = -9990.0f;
                                                else
                                                {
                                                   if(p[2][im2]<-9990)ptt[im2] = -9990.0f;
                                                   else
                                                   {
                                                      if(p[1][im2]<-9990)ptt[im2] = -9990.0f;
                                                      else ptt[im2]= ff[0]*p[0][im2]
                                                          + ff[1]*p[1][im2]
                                                          + ff[2]*p[2][im2]
                                                          + ff[3]*p[3][im2];
                                                   }
                                                }
                                             }

                         if(p[0][im2]>-9990)
                           if(p[3][im2]>-9990)
                              if(p[2][im2]>-9990)
                                if(p[1][im2]>-9990)
                                     ptt[im2]= ff[0]*p[0][im2]
                                                             + ff[1]*p[1][im2]
                                                             + ff[2]*p[2][im2]
                                                             + ff[3]*p[3][im2];
                                  else ptt[im2] = -9990.0f;
                               else ptt[im2] = -9990.0f;
                           else ptt[im2] = -9990.0f;
                         else ptt[im2] = -9990.0f;
发现效果都不理想,请问有没有更好的替代代码?
搜索更多相关主题的帖子: 该段 效率 代码 
2010-11-08 10:50
快速回复:请教如何提高该段代码的执行效率
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023212 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved