-
-
[旧帖] [求助][求助]请教一个关于GetThreadTimes的问题 0.00雪花
-
发表于: 2013-4-22 20:02 1264
-
附代码,附图,一看就明白的
有sleep(1)后获取的时间100次中大部分都是0,跑了好几个小时,屏蔽掉sleep(1)的话时间基本上在48ms左右
与时钟中断有关?还是.......
代码执行 100 * 100万次冒泡排序
【code】
InitializeAndBeginThread();
__int64 qwKernelTimeElapsed, qwUserTimeElapsed, qwTotalTimeElapsed;
int nCount = 0;
for(; nCount <= 100; nCount++)
{
::GetThreadTimes(::GetCurrentThread(), &tCreateTime, &tExitTime, &tKernelTime, &tUserTime);
for (int i=0; i<100000; i++)
{
Func();
::Sleep(1);
}
::GetThreadTimes(::GetCurrentThread(), &tCreateTime, &tExitTime, &tKernelTimeEnd, &tUserTimeEnd);
qwKernelTimeElapsed = FileTimeToQuadWord(&tKernelTimeEnd) - FileTimeToQuadWord(&tKernelTime);
qwUserTimeElapsed = FileTimeToQuadWord(&tUserTimeEnd) - FileTimeToQuadWord(&tUserTime);
qwTotalTimeElapsed = qwKernelTimeElapsed + qwUserTimeElapsed;
double dTime = NsToMsCast(qwTotalTimeElapsed);
std::wstring str;
wchar_t szMsg[MAX_PATH * 5] = {0};
swprintf(szMsg, L"The Programme with Sleep(1) have cost %lf Ms \r\n", dTime);
str = szMsg;
ZeroMemory(szMsg, MAX_PATH * 5);
PushMsg(str);
其中 NsToMsCast 是将时间纳秒转化为毫秒的函数
有sleep(1)后获取的时间100次中大部分都是0,跑了好几个小时,屏蔽掉sleep(1)的话时间基本上在48ms左右
与时钟中断有关?还是.......
代码执行 100 * 100万次冒泡排序
【code】
InitializeAndBeginThread();
__int64 qwKernelTimeElapsed, qwUserTimeElapsed, qwTotalTimeElapsed;
int nCount = 0;
for(; nCount <= 100; nCount++)
{
::GetThreadTimes(::GetCurrentThread(), &tCreateTime, &tExitTime, &tKernelTime, &tUserTime);
for (int i=0; i<100000; i++)
{
Func();
::Sleep(1);
}
::GetThreadTimes(::GetCurrentThread(), &tCreateTime, &tExitTime, &tKernelTimeEnd, &tUserTimeEnd);
qwKernelTimeElapsed = FileTimeToQuadWord(&tKernelTimeEnd) - FileTimeToQuadWord(&tKernelTime);
qwUserTimeElapsed = FileTimeToQuadWord(&tUserTimeEnd) - FileTimeToQuadWord(&tUserTime);
qwTotalTimeElapsed = qwKernelTimeElapsed + qwUserTimeElapsed;
double dTime = NsToMsCast(qwTotalTimeElapsed);
std::wstring str;
wchar_t szMsg[MAX_PATH * 5] = {0};
swprintf(szMsg, L"The Programme with Sleep(1) have cost %lf Ms \r\n", dTime);
str = szMsg;
ZeroMemory(szMsg, MAX_PATH * 5);
PushMsg(str);
其中 NsToMsCast 是将时间纳秒转化为毫秒的函数
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!
赞赏
他的文章
看原图
赞赏
雪币:
留言: