Chinaunix首页 | 论坛 | 博客
  • 博客访问: 64040
  • 博文数量: 25
  • 博客积分: 1050
  • 博客等级: 少尉
  • 技术积分: 239
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-28 20:21
文章分类
文章存档

2010年(25)

我的朋友

分类: C/C++

2010-03-14 18:53:21

写程序要提高程序的效能,就要找出计算量最大的部分,认真的研究这部分程序,
提高这部分效率。GNU的开发工具 gprof 是一个, 编译联接的时候要使用 -pg .

Qprof 是另一个工具, 简单一些只要加上 -g 参考即可。 

使用方式如下:
tlu:~$ cat test.cpp 


/*
* =============================
*
* Filename: test.cpp
*
* Description:
*
* Version: 1.0
* Created: 2009年08月01日 20时10分33秒 CST
* Revision: none
* Compiler: gcc
*
* Author: (),
* Company:
*
* =====================================================================================
*/



long int cal1(long int i){
return i*3;
}

double cal2(double i){
return i*2.0;
}

inline double cal3(double i){
    return i*2.0;
}

int main(void){
long int i = 0;

for(i = 0; i< 100000000; i++){
cal1(i);
cal2(i);
cal3(i);
}
return 0;
}

编译:tlu:~$ g++ -o test.exe -g test.cpp 
运行:
tlu:~$ qprof ./test.exe 
qprof: /home/tlu/test.exe: 168 samples, 168 counts
cal1(long):test.cpp:20                                           11    ( 7%)
cal1(long):test.cpp:21                                           4    ( 2%)
cal1(long):test.cpp:22                                           5    ( 3%)
cal2(double):test.cpp:24                                         13    ( 8%)
cal2(double):test.cpp:25                                         42    ( 25%)
cal2(double):test.cpp:26                                         14    ( 8%)
main:test.cpp:36                                                 1    ( 1%)
main:test.cpp:37                                                 6    ( 4%)
main:test.cpp:38                                                 5    ( 3%)
main:test.cpp:35                                                 2    ( 1%)
cal3(double):test.cpp:28                                         9    ( 5%)
cal3(double):test.cpp:29                                         40    ( 24%)
cal3(double):test.cpp:30                                         16    ( 10%)
阅读(415) | 评论(0) | 转发(0) |
0

上一篇:MAC冲突窗口-无线网络102

下一篇:逝去的SUN

给主人留下些什么吧!~~