LoginSignup
0
0

More than 1 year has passed since last update.

計測時間(分秒)を返す VBScript

Last updated at Posted at 2021-12-26

※ 一応、コンマ何秒(小数点以下3桁)まで計測するが、ミリ単位は正確ではない

GetLapTime.vbs
Option Explicit
'// 実行結果
Dim startTime, num, msg
startTime = Timer
num = 304250263527210
msg = num & " の素因数分解は[ " & PrimeFact(num) & " ]"
msg = msg & vbCrLf & "計測時間: " & GetLapTime(startTime)
Msgbox msg
'// 引数 start_time に開始時間を与えてやると、
'// 開始時間からこのスクリプトが実行されるまでの
'// 時間を分秒で返す。

Function GetLapTime(ByVal start_time)

    Dim lapTime, m, s, f

    lapTime = Timer - start_time
    m = Int(lapTime / 60)
    s = Int(lapTime) Mod 60
    f = Int((lapTime - Int(lapTime)) * 1000)

    GetLapTime = m & " 分 " & s & " 秒 " & f

End Function
'// 素因数分解の結果を返す(15桁以下)

Function PrimeFact(ByVal num)

    Dim i, str

    i = 2
    Do While num / i = Int(num / i)
        If num = i Then Exit Do
        str = str & i & " "
        num = num / i
    Loop

    For i = 3 To Int(num^0.5) Step 2
        Do While num / i = Int(num / i)
            If num = i Then Exit Do
            str = str & i & " "
            num = num / i
        Loop
    Next

    PrimeFact = str & num

End Function
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0