岁月流转,往昔空明

C++博客 首页 新随笔 联系 聚合 管理
  118 Posts :: 3 Stories :: 413 Comments :: 0 Trackbacks

To: 很土:我确实没有搜到任何相关的信息,所以还请你指点。谢谢。

我昨天在写函数然后测试优化选项的时候,非常奇怪的发现,如果打开了

运行时检测 选项中的 堆栈帧检测 ,代码性能就会疯狂的攀升一个数量级

然而从理论上来说,由于堆栈帧检测添加了Check ESP的CRT函数调用(实际的汇编也是如此),性能应该略有下降才是,但是我不知道为什么它的性能居然能极大幅度的提高。

#include "stdafx.h"
#include 
<math.h>
#include 
<float.h>
#include 
<emmintrin.h> 
#include 
<windows.h>
#include 
<d3dxmath.h>

using namespace std;

 
struct __declspec(align(16)) Matrix {
float m[4][4];
}
;

class Profiler
{
public:
LARGE_INTEGER s;
LARGE_INTEGER e;

__int64 Begin() 
{
QueryPerformanceCounter(
&s);

return s.QuadPart;
}


__int64 End() 
{
QueryPerformanceCounter(
&e);

return e.QuadPart - s.QuadPart;
}

}
;

int Multiply(float o[][4], const float a[][4], const float b[][4], int i)
{
o[
0][0= a[0][0* b[0][0+ a[0][1* b[1][0+ a[0][2* b[2][0+ a[0][3* b[3][0];
o[
0][1= a[0][0* b[0][1+ a[0][1* b[1][1+ a[0][2* b[2][1+ a[0][3* b[3][1];
o[
0][2= a[0][0* b[0][2+ a[0][1* b[1][2+ a[0][2* b[2][2+ a[0][3* b[3][2];
o[
0][3= a[0][0* b[0][3+ a[0][1* b[1][3+ a[0][2* b[2][3+ a[0][3* b[3][3];

o[
1][0= a[1][0* b[0][0+ a[1][1* b[1][0+ a[1][2* b[2][0+ a[1][3* b[3][0];
o[
1][1= a[1][0* b[0][1+ a[1][1* b[1][1+ a[1][2* b[2][1+ a[1][3* b[3][1];
o[
1][2= a[1][0* b[0][2+ a[1][1* b[1][2+ a[1][2* b[2][2+ a[1][3* b[3][2];
o[
1][3= a[1][0* b[0][3+ a[1][1* b[1][3+ a[1][2* b[2][3+ a[1][3* b[3][3];

o[
2][0= a[2][0* b[0][0+ a[2][1* b[1][0+ a[2][2* b[2][0+ a[2][3* b[3][0];
o[
2][1= a[2][0* b[0][1+ a[2][1* b[1][1+ a[2][2* b[2][1+ a[2][3* b[3][1];
o[
2][2= a[2][0* b[0][2+ a[2][1* b[1][2+ a[2][2* b[2][2+ a[2][3* b[3][2];
o[
2][3= a[2][0* b[0][3+ a[2][1* b[1][3+ a[2][2* b[2][3+ a[2][3* b[3][3];

o[
3][0= a[3][0* b[0][0+ a[3][1* b[1][0+ a[3][2* b[2][0+ a[3][3* b[3][0];
o[
3][1= a[3][0* b[0][1+ a[3][1* b[1][1+ a[3][2* b[2][1+ a[3][3* b[3][1];
o[
3][2= a[3][0* b[0][2+ a[3][1* b[1][2+ a[3][2* b[2][2+ a[3][3* b[3][2];
o[
3][3= a[3][0* b[0][3+ a[3][1* b[1][3+ a[3][2* b[2][3+ a[3][3* b[3][3];

return i / 1000;
}


int _tmain(int argc, _TCHAR* argv[])
{
__declspec(align(
16)) D3DXVECTOR3 v(2.0f,2.0f,2.0f);
HANDLE hp 
= GetCurrentProcess();
HANDLE ht 
= GetCurrentThread();

SetPriorityClass(hp, REALTIME_PRIORITY_CLASS);
SetThreadPriority(ht, THREAD_PRIORITY_TIME_CRITICAL);

Profiler p;
Matrix m, m1, m2;
memset(m.m, 
016);
memset(m1.m, 
016);

m.m[
0][0= 1.0f;
m.m[
0][1= 2.0f;
m.m[
0][2= 3.0f;
m.m[
0][3= 4.0f;

m.m[
1][0= 5.0f;
m.m[
1][1= 6.0f;
m.m[
1][2= 7.0f;
m.m[
1][3= 8.0f;

int y = 0;
int t = 0;

p.Begin();
for(int i = 0; i < 100000++i)
{
= Multiply(m2.m, m.m, m1.m, i);
+= t;
}

__int64 x 
= p.End();

cout 
<< x << " MatrixMultiply C"<< y << endl;

SetPriorityClass(hp, NORMAL_PRIORITY_CLASS);
SetThreadPriority(ht, THREAD_PRIORITY_NORMAL);

system(
"pause");

return 0;
}




以上为代码。。。希望能有知道的帅哥做出解答。。。谢谢了!

posted on 2005-11-28 20:52 空明流转 阅读(812) 评论(4)  编辑 收藏 引用

评论

# re: VC71的一个超奇怪问题 2005-11-29 08:49 很土
这种问题完全可以google就知道,和另外一个"怎么链接动态库"一样的,提问之前都没有google过...,至少在你们的文字中,我没有看到google过的痕迹.
  回复  更多评论
  

# re: VC71的一个超奇怪问题 2005-11-29 09:46 空明流转
Google 了,但是没有找到。望楼上的高人指点。  回复  更多评论
  

# re: VC71的一个超奇怪问题 2005-12-08 08:55 神杀中龙
空明流转 找到你了,我是神杀中龙  回复  更多评论
  

# re: VC71的一个超奇怪问题 2008-08-19 14:46 沈臻豪(foxtail)
这个问题高深了 要找专门搞优化的人来看看  回复  更多评论
  


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理