Stopwatch.Frequency フィールド
アセンブリ: System (system.dll 内)
構文
タイマ頻度は、タイマの精度と解像力を示します。たとえば、毎秒 200 万のタイマ刻みのタイマ頻度は、タイマ刻みあたり 500 ナノ秒のタイマ解像力と等価です。つまり、1 秒は 10 億ナノ秒と等しいため、毎秒 200 万のタイマ刻みのタイマ頻度は、10 億ナノ秒あたり 200 万のタイマ刻みと等しくなります。これをさらに簡略化すると、500 ナノ秒あたり 1 タイマ刻みになります。
Frequency 値は、基になるタイミング機構の解像力によって異なります。インストールされているハードウェアおよびオペレーティング システムが高解像力のパフォーマンス カウンタをサポートする場合、Frequency 値はそのカウンタの頻度を反映します。それ以外の場合、Frequency 値はシステム タイマ頻度に基づきます。
Stopwatch 頻度は、インストールされているハードウェアおよびオペレーティング システムによって異なるため、Frequency 値はシステムの実行中は変化しません。
Stopwatch クラスの頻度および解像力を表示する例を次に示します。
Public Shared Sub DisplayTimerProperties() ' Display the timer frequency and resolution. If Stopwatch.IsHighResolution Then Console.WriteLine("Operations timed using the system's high-resolution performance counter.") Else Console.WriteLine("Operations timed using the DateTime class.") End If Dim frequency As Long = Stopwatch.Frequency Console.WriteLine(" Timer frequency in ticks per second = {0}", frequency) Dim nanosecPerTick As Long = 1000000000 / frequency Console.WriteLine(" Timer is accurate within {0} nanoseconds", nanosecPerTick) End Sub
public static void DisplayTimerProperties() { // Display the timer frequency and resolution. if (Stopwatch.IsHighResolution) { Console.WriteLine("Operations timed using the system's high-resolution performance counter."); } else { Console.WriteLine("Operations timed using the DateTime class."); } long frequency = Stopwatch.Frequency; Console.WriteLine(" Timer frequency in ticks per second = {0}", frequency); long nanosecPerTick = (1000L*1000L*1000L) / frequency; Console.WriteLine(" Timer is accurate within {0} nanoseconds", nanosecPerTick); }
void DisplayTimerProperties() { // Display the timer frequency and resolution. if ( Stopwatch::IsHighResolution ) { Console::WriteLine( "Operations timed using the system's high-resolution performance counter." ); } else { Console::WriteLine( "Operations timed using the DateTime class." ); } Int64 frequency = Stopwatch::Frequency; Console::WriteLine( " Timer frequency in ticks per second = {0}", frequency ); Int64 nanosecPerTick = (1000L * 1000L * 1000L) / frequency; Console::WriteLine( " Timer is accurate within {0} nanoseconds", nanosecPerTick ); }
public static void DisplayTimerProperties() { // Display the timer frequency and resolution. if (Stopwatch.IsHighResolution) { Console.WriteLine("Operations timed using the system's " + "high-resolution performance counter."); } else { Console.WriteLine("Operations timed using the DateTime class."); } long frequency = Stopwatch.Frequency; Console.WriteLine(" Timer frequency in ticks per second = {0}", (Int64)frequency); long nanoSecPerTick = (1000L * 1000L * 1000L) / frequency; Console.WriteLine(" Timer is accurate within {0} nanoseconds", (Int64)nanoSecPerTick); } //DisplayTimerProperties
Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- Stopwatch.Frequency フィールドのページへのリンク