加入比较短时间的Sleep()一般对时效性影响不大,但能极大地降低CPU占用。
- 比如,这里我们用coolfun::UI_suspend()等待按键函数的源码来举例:
#include<conio.h>
#include<iostream>
#include<windows.h>
using namespace std;
int main()
{
cout << "<< 按任意键继续... ";
for (int i = 0; _kbhit() == 0;) //等待按键
{
switch (i++) //选择打印最后的一个字符,使之有动画效果
{
case 0:cout << "\b/"; break;
case 1:cout << "\b-"; break;
case 2:cout << "\b\\"; break;
case 3:
{
cout << "\b|";
i = 0;
}break;
}
//Sleep(100); //暂停100毫秒(1秒 = 1000毫秒)
}
}
- 效果:
- 但是它的CPU占用相当的高,一直了 8% 左右,而这还仅仅是一个简单的动画功能。
- 那接下来我们在循环内加一条Sleep():
- 然后再来看看它的CPU占用:
- 可以看到,显示的是CPU占用 0%,显然是因为占用太低了,所以才显示了 0%。
- 这句Sleep(100),暂停的100毫秒对用户来说基本没感觉,但却大幅度降低了CPU占用,而且动画效果甚至更舒服了:
where can you buy amoxicillin over the counter: com pharm – amoxicillin price without insurance
cheap amoxicillin 500mg: buy amoxil online – medicine amoxicillin 500
buy priligy: cheap priligy – priligy max pharm
I quite like looking through an article that can make people think. Also, many thanks for allowing me to comment.
buy prednisone canadian pharmacy: prednisone ray pharm – can you buy prednisone without a prescription
priligy max pharm: max pharm – priligy max pharm
order amoxicillin 500mg: Com Pharm – over the counter amoxicillin
priligy max pharm: priligy – buy dapoxetine online
dapoxetine online: max pharm – dapoxetine price
canada pharmacy prednisone: cheap prednisone – buy prednisone without a prescription best price
amoxicillin 500 mg: amoxil – where can you get amoxicillin
where buy cheap clomid pill: clomid rex pharm – how to buy clomid without dr prescription
amoxicillin 500 mg: buy amoxil online – amoxicillin 500 tablet
generic amoxicillin 500mg: Amoxicillin Com Pharm – over the counter amoxicillin
Priligy tablets: buy dapoxetine online – priligy max pharm
amoxicillin azithromycin: Amoxicillin buy online – amoxicillin discount coupon
how much is prednisone 10 mg: order Prednisone – order prednisone online no prescription