|
|
对不起,我不会VC,所以做成了VB。(如果是VC的话就可以多线程方式执行,不会看上去像死机了)
此程序采用最传统、最暴力的方法测试CPU:
对随机基数进行平方、开方、对数、反对数等暴力整数、浮点计算指定次,检验性能。
注:由于此测试手段非常“暴力”、“野蛮”,霸占CPU,而且是单线程程序,所以可能在计算时看上去像死机,请谅解(这是单线程程序的不足)!
如果是多核CPU,建议按CPU核心数量多开测试,结果更准确!
源码:- Option Explicit
- Private Sub Command1_Click()
- Dim jsw, cs, i, ii As Integer
- Dim StartTime, EndTime As Double
- jsw = Form1.Text1.Text
- cs = Form1.Text2.Text * 1000000
- Dim zfc As String
- zfc = "1**6789"
- Form1.Label11.Caption = "正在计算"
- Form1.Label8.Caption = ""
- StartTime = Timer
- For i = 1 To cs
- Randomize
- Dim ranmod As String
- Dim temp, temp2, temp3, temp4, temp5, temp1 As Double
- ranmod = "0"
- For ii = 1 To jsw
- ranmod = ranmod & Mid(zfc, 1 + Int(Len(zfc) * Rnd), 1)
- Next ii
- temp = ranmod ^ 2
- temp1 = Sqr(temp)
- temp2 = Log(temp1)
- temp3 = Exp(temp2)
- temp4 = Atn(temp3)
- temp5 = Tan(temp4)
- temp = temp + 1
- temp = temp * ranmod - 5
- Next
- EndTime = Timer
- Form1.Label8.Caption = EndTime - StartTime
- Form1.Label11.Caption = "计算完成"
- End Sub
复制代码
[ 本帖最后由 2011czmxbb52 于 2012-7-31 09:57 编辑 ] |
|