这里用c#编写cpu的压力测试程序。
public void Calculate(object arg)
{
Random ra = new Random();
Thread.Sleep(ra.Next(10, 1000));
pinghost();
FileWrite(arg.ToString());
}
private void FileWrite(string arg)
{
//获得字节数组
int fsLen = (int)fs.Length;
byte[] heByte = new byte[fsLen];
int r = fs.Read(heByte, 0, heByte.Length);
string myStr = System.Text.Encoding.UTF8.GetString(heByte);
string xyPointer = string.Format("X: {0}, Y: {1}", this.Location.X.ToString(), this.Location.Y.ToString());
string highWidth = string.Format("\nW: {0}, H: {1}", this.Width.ToString(), this.Height.ToString());
byte[] data = System.Text.Encoding.Default.GetBytes(xyPointer + highWidth + arg);
//开始写入
fs.Write(data, 0, data.Length);
}
不断的增加CPU的压力。
资源:下载