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


    今天谈到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
    

        



    @ Mayuko

  • 相关阅读:
    logging模块,序列化,range模块
    生成器以及推导式
    递归,自定义模块,time模块,datetime
    装饰器,内置函数
    函数名的使用以及第一类对象,闭包,迭代器
    python文件操作
    面向对象
    os sys hashlib
    文件操作
    logging模块
  • 原文地址:https://www.cnblogs.com/mayuko/p/4567524.html
Copyright © 2020-2023  润新知