vs2010 在函数级别设置优化
2015-06-26 16:36
267 查看
平时开发的时候,为了方便调试,visualstudio的Configuration设置成Release。
同时为了事后调试,Optimization总是设置成Disabled。这样做是方便查看变量的数值。
但遇到计算密集的功能实现,优化关闭还是挺费时间的。
voidcalc(intnMax)
{
intnTotal=0;
for(intindex=0;index<nMax;index++)
{
nTotal=0;
for(intsubIndex=index;subIndex<nMax+index;subIndex++)
{
nTotal+=subIndex;
}
}
}
最初我的想法是project的优化关闭,相关文件的优化打开,测试后发现没有什么作用。
参考visualstudio的帮助后,发现可以针对函数进行优化。
这样做考虑其他方法依旧可以事后调试。
在函数前后增加#pragmaoptimize即可
#pragmaoptimize("gs",on)
voidcalc(intnMax) { intnTotal=0; for(intindex=0;index<nMax;index++) { nTotal=0; for(intsubIndex=index;subIndex<nMax+index;subIndex++) { nTotal+=subIndex; } } }#pragmaoptimize("gs",off)
经过测试,针对函数的优化,性能和project优化相当。
未优化前:0.67秒
优化后:0.00秒
这样以后事后调试还是很方便的。
测试环境:
ide:vs2010
项目:console
Configuration:Release。
Optimization:Disabled
实现代码:
#include"stdafx.h"
#include<Windows.h>
#pragmaoptimize("gs",on)
voidcalc(intnMax) { intnTotal=0; for(intindex=0;index<nMax;index++) { nTotal=0; for(intsubIndex=index;subIndex<nMax+index;subIndex++) { nTotal+=subIndex; } } }#pragmaoptimize("gs",off)
voidretry(intnMin)
{
intnTry=0;
nTry=nMin;
}
int_tmain(intargc,_TCHAR*argv[])
{
LARGE_INTEGER freq ={0};
LARGE_INTEGER beginPerformanceCount ={0};
LARGE_INTEGER closePerformanceCount ={0};
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&beginPerformanceCount);
calc(10000);
QueryPerformanceCounter(&closePerformanceCount);
retry(2020);
doubledelta_seconds=(double)(closePerformanceCount.QuadPart-beginPerformanceCount.QuadPart)/freq.QuadPart;
printf("%f",delta_seconds);
getchar();
return0;
}
相关链接:
https://msdn.microsoft.com/en-us/library/chh3fb0k(v=vs.100).aspx
同时为了事后调试,Optimization总是设置成Disabled。这样做是方便查看变量的数值。
但遇到计算密集的功能实现,优化关闭还是挺费时间的。
最初我的想法是project的优化关闭,相关文件的优化打开,测试后发现没有什么作用。
参考visualstudio的帮助后,发现可以针对函数进行优化。
这样做考虑其他方法依旧可以事后调试。
在函数前后增加#pragmaoptimize即可
voidcalc(intnMax) { intnTotal=0; for(intindex=0;index<nMax;index++) { nTotal=0; for(intsubIndex=index;subIndex<nMax+index;subIndex++) { nTotal+=subIndex; } } }#pragmaoptimize("gs",off)
经过测试,针对函数的优化,性能和project优化相当。
未优化前:0.67秒
优化后:0.00秒
这样以后事后调试还是很方便的。
测试环境:
ide:vs2010
项目:console
Configuration:Release。
Optimization:Disabled
实现代码:
#include<Windows.h>
#pragmaoptimize("gs",on)
voidcalc(intnMax) { intnTotal=0; for(intindex=0;index<nMax;index++) { nTotal=0; for(intsubIndex=index;subIndex<nMax+index;subIndex++) { nTotal+=subIndex; } } }#pragmaoptimize("gs",off)
voidretry(intnMin)
{
intnTry=0;
nTry=nMin;
}
int_tmain(intargc,_TCHAR*argv[])
{
LARGE_INTEGER freq ={0};
LARGE_INTEGER beginPerformanceCount ={0};
LARGE_INTEGER closePerformanceCount ={0};
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&beginPerformanceCount);
calc(10000);
QueryPerformanceCounter(&closePerformanceCount);
retry(2020);
doubledelta_seconds=(double)(closePerformanceCount.QuadPart-beginPerformanceCount.QuadPart)/freq.QuadPart;
printf("%f",delta_seconds);
getchar();
return0;
}
相关链接:
相关文章推荐
- 一个很好的语法分析和词法分析器的实现
- Jenkins -- Subversion 的用户名和密码
- http://52test.org/posts/SIPp-IP-Telephone-Server-Performance-Testing.html
- Redis,Memcache,mongoDB的区别
- php使用MySQL保存session会话的方法
- Java使用SOAP获取webservice实例解析
- Python中用于计算对数的log()方法
- STM32F4xx时钟理解
- ARM9中断处理学习
- winform中利用反射实现泛型数据访问对象基类(1)
- 7种GRE填空的快速解题方法
- MYSQL的存储过程入门游标
- 字符创去除首尾空格,合并串中的多个空格为一个空格
- Linux下rar命令详解
- 二分插入排序
- Spring Model
- 前台字符串过滤_前台进行条件查询
- sublime基本命令和使用
- 那些逐步掌握的JavaScript(开篇)
- block与刷新(collectionView、tableview)