关于GetTickCount函数的用法
来源:互联网 发布:linux程序常驻 编辑:程序博客网 时间:2024/05/01 16:42
#include <windows.h>#include <iostream>using namespace std;int main(){ int a[200][200]; // 数组改大点,不要担心你的宝贝机器会受不了,如果只是区区赋值而已,它眼都不眨一气呵成。 DWORD begin,end,time; begin = GetTickCount(); for(int i =0; i<200; i++) { for(int j=0; j<200; j++) { a[i][j] = i+j; std::cout << a[i][j] << std:: endl; // 让它一个一个输出,这个可是比较可观的“活儿” } } end = GetTickCount(); cout<<"begin="<<begin<<endl; cout<<"end="<<end<<endl; time = end - begin; cout<<time; return 0;}
上面是GetTickCount函数最简单的用法,
让CPU占用率固定在50%,为一条直线:
int main()
{
const DWORD busyTime=10; //设定CPU忙的时间为10ms
const DWORD idleTime=busyTime; //CPU空闲的时间与忙的时间相等
DWORD starTime=0;
while(1) //死循环,不关闭程序CPU的占用率则一直保持在50%
{
starTime=GetTickCount();
while(GetTickCount()-starTime<=busyTime) //让CPU忙的循环
;
Sleep(idleTime); //CPU闲的时间
}
return 0; }
*******************************************************************************************************************
你就当这个函数是得到机器开机后的到现在的毫秒数就行.通常是用在相对时间判断上,典型的例子是用在游戏中,控制每秒钟的帧数.//下面的代码把图像切换控制在33帧/秒int iBegin=GetTickCount();int iNow;while(TRUE){ iNow=GetTickCount(); if (iNow-iBegin<30) continue; iBegin=iNow; 切换一幅图像.}
0 0
- 关于GetTickCount函数的用法
- SetTimer函数和GetTickCount()函数的用法
- SetTimer函数和GetTickCount()函数的用法
- 【总结】GetTickCount() 函数的作用和用法
- GetTickCount() 函数的作用和用法!
- GetTickCount() 函数的作用和用法
- GetTickCount() 函数的作用和用法
- GetTickCount()函数的作用和用法
- GetTickCount() 函数的使用
- GetTickCount()函数的陷阱!
- linux上的GetTickCount函数
- linux上的GetTickCount函数
- Linux上的GetTickCount函数
- rand()和srand()GetTickCount函数用法
- rand()和srand()GetTickCount函数用法
- GetTickCount() 用法
- GetTickCount函数
- GetTickCount函数
- M70003中型Android平板电脑亦称IPED 13价格ipad的
- 一个View加了同时setOnClickListener,setOnTouchListener监听器点击异常
- 蚊子132想推广开,必须有一个UI库
- android下的android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork错误
- 用于二次开发企业即时通讯源码
- 关于GetTickCount函数的用法
- JAVA中去除空格的方法
- 三角形顺时针和逆时针的判定
- Windows消息大全
- LG的Optimus 3D预订构建多任务手机
- LG擎天柱540亿吨
- Alfresco中Search In Folder功能(在指定文件夹下搜索文件)
- ASP从零开始学习笔记(一)
- 添加引导页 (引导页的图片根据网络请求获取,张数不一定)