' stopwatch.vb Imports System Imports System.Diagnostics Class StopWatchSample Shared Sub Main() Dim sw As New Stopwatch sw.Start() System.Threading.Thread.Sleep(1000) sw.Stop() ' ミリ秒単位で出力 Dim millisec As Long = sw.ElapsedMilliseconds Console.WriteLine(millisec) ' 出力例:998 ' TimeSpan構造体で書式付き表示 Dim ts As TimeSpan = sw.Elapsed Console.WriteLine(ts) ' 出力例:00:00:00.9984668 ' 高分解能なタイマが利用可能か Console.WriteLine(Stopwatch.IsHighResolution) ' 出力例:True ' タイマ刻み回数 Dim ticks As Long = sw.ElapsedTicks Console.WriteLine(ticks) ' 出力例:2988141812 ' タイマの1秒あたりの刻み回数 Console.WriteLine(Stopwatch.Frequency) ' 出力例:2992730000 ' より詳細な秒数 Dim sec As Double = sw.ElapsedTicks / Stopwatch.Frequency Console.WriteLine(sec) ' 出力例:0.998466888760429 End Sub End Class ' コンパイル方法:vbc stopwatch.vb