69,373
社区成员
发帖
与我相关
我的任务
分享
char* buf;
class A
{
public:
int width;
int height;
void test2();
};
void A::test2()
{
for(int j=0;j<height;j++)
for(int i=0;i<width;i++)
{
buf[j*width+i]=0;
}
}
void test1(int height,int width)
{
for(int j=0;j<height;j++)
for(int i=0;i<width;i++)
{
buf[j*width+i]=0;
}
}
void main()
{
A ma;
ma.width=10000;
ma.height=10000;
buf=new char[ma.width*ma.height];
//test1和test2两个函数代码相同,但test2的耗时比test1多15%
test1(ma.height,ma.width);
ma.test2();
}