获取运行时间 精度很高的算法2

bool SPTI(TimeInterval * t)

{

LONGLONG i,i2;

DWORD n,nfr,n3,n2,n1;

if(QueryPerformanceCounter(&(t->t2)) == FALSE){

t->mks = 0;

sprintf(t->str,”Not supported”);

return FALSE;

}

i = t->t1.QuadPart;

i2 = t->t2.QuadPart;

i2 = i2-i;

if(i2 > 0xffffffff){

sprintf(t->str,”To big interval”);

t->mks = 0xffffffff;

return TRUE;

}

i = t->fr.QuadPart;

n = (DWORD)i2;

nfr = (DWORD)i;

n3 = n/nfr;

t->mks = n3*1000000;

n2 = n3*nfr;

n-=n2;

n*=1000;

n2 = n/nfr;

t->mks+=(n2*1000);

n1 = n2*nfr;

n-=n1;

n*=1000;

n1 = n/nfr;

t->mks+=(n1);

sprintf(t->str,”%d sec %d mls %d mcs”,n3,n2,n1);

return TRUE;

}

执行结果

0 sec 3 mls 792 mcs
Press any key to continue

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>