LONGLONG start,finish;
LONGLONG totalTime;
start = GetTickCount();
DoubleMatrix1D a;
a.setbounds(0,10000000);
/* 待统计时间的代码段 开始 */
for (int i = a.getlowbound(1);i<a.gethighbound(1); i++)
{
memset(&a(i),0,sizeof(a));
}
/* 待统计时间的代码段 结束 */
finish = GetTickCount();
totalTime = finish - start;
cout<<"Cost0 "<<totalTime<<"ms"<<endl;
start = GetTickCount();
DoubleMatrix1D b;
b.setbounds(0,10000000);
/* 待统计时间的代码段 开始 */
for (int i = b.getlowbound(1);i<b.gethighbound(1); i++)
{
b(i) = 0.0;//memset(&a(1),0,sizeof(a));
}
/* 待统计时间的代码段 结束 */
finish = GetTickCount();
totalTime = finish - start;
cout<<"Cost1 "<<totalTime<<"ms"<<endl;
LONGLONG totalTime;
start = GetTickCount();
DoubleMatrix1D a;
a.setbounds(0,10000000);
/* 待统计时间的代码段 开始 */
for (int i = a.getlowbound(1);i<a.gethighbound(1); i++)
{
memset(&a(i),0,sizeof(a));
}
/* 待统计时间的代码段 结束 */
finish = GetTickCount();
totalTime = finish - start;
cout<<"Cost0 "<<totalTime<<"ms"<<endl;
start = GetTickCount();
DoubleMatrix1D b;
b.setbounds(0,10000000);
/* 待统计时间的代码段 开始 */
for (int i = b.getlowbound(1);i<b.gethighbound(1); i++)
{
b(i) = 0.0;//memset(&a(1),0,sizeof(a));
}
/* 待统计时间的代码段 结束 */
finish = GetTickCount();
totalTime = finish - start;
cout<<"Cost1 "<<totalTime<<"ms"<<endl;
运行结果: