Previously in < programming beauty > read the article about controlling CPU usage in Task Manager. I feel very mean. Always wanted to do it myself once. But I have a limited level of C language. Therefore, it is not possible to practice this process directly by finding code.
But I've been using JavaScript a lot lately, so I thought about using JavaScript. The results are not bad. The code is below, just build an HTML file on the desktop, put the code in, and open it with a browser to see. Because I use the machine is dual-core, so the effect is not very good. Hope to have a master to help me improve this program.
Copy Code code as follows:
<script type= "Text/javascript" >
var SPLIT = 0.01;
var COUNT = 200;
var PI = 3.14159265;
var INTERVAL = 150;
var busyspan=new Array (); Array of busy times
var idlespan=new Array (); Array of idle times
function ShowMsg ()
{
var half=interval/2;
var radian = 0.0;
var i=0;
for (i = 0;i<count; i++)
{
Busyspan[i] = (half + (Math.sin (PI * radian) * half));
Idlespan[i] = Interval-busyspan[i];
Radian+=split;
}
Cystime ();
return 0;
}
var j=0;var flag=0;
function Cystime ()
{
J=j%count;
Busy
flag=0;
var nowobj=new Date ();
var nowms=nowobj.gettime ();
var newms=nowms;
while ((NEWMS-NOWMS) <busyspan[j])
{nowobj=new Date (); Newms=nowobj.gettime ();}
Idle
var idlt=settimeout (' Cystime () ', idlespan[j]);
j + +;
}
</script>
<body >
<input onclick= "showmsg ()" type= "button" value= "Start"/>
</body>
If you want to get the CPU approximately flat-curve, you can
Task Manager-> Performance,-> Resource Monitor view