按下Ctrl+Alt+Del,会出现一个叫“windows任务管理器”的窗口。在它的“性能”标签中有个叫“CPU使用率”的东西。
其实这个东西很像是人品。。或者说是RP,比如说在运行这个程序的时候(C#):
using System;
using System.Collections.Generic;
using System.Text;
namespace cputest
{
class Program
{
const int d = 100;//每个运行周期,这个数越小波形的周期越小。
const int e = 13; //误差,根据cpu实际情况和d的值而定。
static void Main(string[] args)
{
int u = 0;
while (true)
{
int i = Environment.TickCount;
int r = (int)(d * Math.Abs(Math.Sin(u/50.0)));
while (Environment.TickCount - i < r) ;
System.Threading.Thread.Sleep(d-r+e);
u++;
}
}
}
}
结果就是上图。
虽然和正弦函数还是有一些差距。。不过我觉得是C#语言的问题,有一些像Math.Abs和Math.Sin之类的函数的效率问题使正弦函数似乎没有零点。
或者改一下r的取值,曲线就会像r表示的函数的图像一样了。