Super Pi-计算10000位圆周率需要多少时间?

时间:2022-02-05 18:31:54

今天谈到CPU的计算功率,想到网上流传的Super Pi这个圆周率计算器。

两个Text,一个Timer,一个Command,就可完成Super Pi的工作~

Option Explicit
'Copyright (c) 2015,烟台大学计算机学院
'All right reserved.
'作者:邵帅
'文件:工程1.vbp
'完成时间:2015年04月03日
'版本号:v1.0
Sub getpi(Optional ByVal nums As Long = 10000)
nums = nums \ 5
Dim max As Long, laptime As Single, result() As String
Dim i, j As Long, d As Long, t, g, r, k As Long, f()
laptime = Timer
max = 10 * nums
ReDim f(1 To max)
ReDim result(nums)
result(0) = vbCrLf
For i = 1 To max
DoEvents
f(i) = 30000
Next
For j = max To 1 Step -10
t = 0
DoEvents
For i = j To 1 Step -1
DoEvents
If j = max Then
t = t + f(i) * 1000000
Else
t = t + f(i) * 100000
End If
r = 8 * i * (2 * i + 1)
f(i) = t - Int(t / r) * r
d = 2 * i - 1
t = Int(t / r) * d * d
Next
k = k + 1
result(k) = Format(Int(g + t / 100000) Mod 100000, "00000")
If k Mod 20 = 0 Then result(k) = result(k) & vbCrLf
If k Mod 200 = 0 Then result(k) = result(k) & "---[" & k * 5 & "]---" & vbCrLf
g = t Mod 100000
Next
Text1.Text = "3." & Join(result, " ")
Open "C:\1.txt" For Output As #1
Print #1, Text1.Text
Close #1
Timer1.Enabled = False
End Sub
Private Sub Command1_Click()
  Timer1.Enabled = True
  getpi Text2.Text
  MsgBox "计算完成,共用时" + s1.Caption + "秒。" & vbCrLf & "计算结果将在C:\1.txt下显示。"
End Sub

Private Sub Timer1_Timer()
  s1.Caption = s1.Caption + 1
End Sub

Super Pi-计算10000位圆周率需要多少时间?     Super Pi-计算10000位圆周率需要多少时间?

Super Pi-计算10000位圆周率需要多少时间?


@ Mayuko