|
|
这里有一段代码:
#include <iostream>
#include <windows.h>
using namespace std;
struct PaletteTable
{
DWORD colorref;
int index;
// int a;
// int b;
};
void main()
{
PaletteTable palettetable[256] ;
for( i=0;i<256;i++)
{
palettetable.index=i;
palettetable.colorref=255*65536;
}
int r=255,b=255,g=255;
DWORD colorref=255*65536;
BYTE* psurf=new BYTE;
DWORD time=GetTickCount();
for(int i=0;i<14400;i++)
{
for( int j=0;j<1040;j++)
{
colorref=b*65536+g*256+r;
int index=256/2;
int half=0;
if(colorref<=palettetable[129].colorref&&colorref>=palettetable[127].colorref)
{
if(colorref>=palettetable[128].colorref + ((palettetable[129].colorref- palettetable[128].colorref)>>1)
*psurf= palettetable[129].index;
else if (colorref>=palettetable[127].colorref + ((palettetable[128].colorref- palettetable[127].colorref)>>1)
* psurf= palettetable[half+index].index;
else
* psurf= palettetable[half+index-1].index;
}
else if(colorref<=palettetable[128].colorref)
index=index>>1;
else
{
half+=index;
index=index>>1;
}
}
}
cout<<GetTickCount()-time;
}
注意:你不需要知道这一大段代码是做什么的,
你只需要知道cout<<GetTickCount()-time; 显示以上的代码所花的时间,
和PaletteTable这个结构
在这里我要说的是PaletteTable这个结构,注意变量a,b;当我把a的注释去掉以后,花费的时间变多,
当我再把b的注释去掉以后,花费的时间又变正常了,这是为什么?
变量a,b我从来没有用过,为什么会出现这种情况?
|
|