中の技術日誌
 ホーム / 上へ

わんくまライブラリ Wankuma.Interop.InteropQueryPerformanceCounterクラス Version1

2005/07/19

この文書はVisual Studio 2003(.NET1.1)をベースに記述されています。それ以降のバージョンや、あなたが読んでいる時点では変更されている可能性があります。
またバージョンアップされている場合にはなんらかかの不具合を含んでいる可能性があります。

新バージョンへ
Wankuma.Interop.InteropQueryPerformanceCounter2d.htm

ドキュメントへ
Wankuma.Interop.InteropQueryPerformanceCounter1d.htm

ソースファイル直接ダウンロードへ
Wankuma.Interop.InteropQueryPerformanceCounter1c.txt

利用規約へ
../kiyaku.htm

#region Using
using System;
using System.Runtime.InteropServices;
#endregion

namespace Wankuma.Interop
{
  /// <summary>
  /// QueryPerformanceCounter を使ったパフォーマンスカウンタです。
  /// </summary>
  public class InteropQueryPerformanceCounter
  {
    #region P/Invoke
    [DllImport("kernel32.dll")]
    extern static short QueryPerformanceCounter(ref long x);
    [DllImport("kernel32.dll")]
    extern static short QueryPerformanceFrequency(ref long x);
    #endregion
    #region メンバ
    private long _StratTime = 0;
    private long _EndTime = 0;
    private long _Frequency = 0;
    #endregion
    #region public long Frequency
    /// <summary>
    /// 分解能を取得します。
    /// </summary>
    /// <exception cref="NotSupportedException">このシステムではQueryPerformanceCounterが対応していません。</exception>
    public long Frequency
    {
      get
      {
        if (this._Frequency != 0 )
        {
          return this._Frequency;
        }
        else
        {
          if ( QueryPerformanceFrequency(ref this._Frequency) == 0 )
          {
            throw new NotSupportedException("このシステムでは対応していません。");
          }
          else
          {
            return this._Frequency;
          }
        }
      }
      
    }
    #endregion
    #region public void Start()
    /// <summary>
    /// 計測を開始します
    /// </summary>
    /// <exception cref="NotSupportedException">このシステムではQueryPerformanceCounterが対応していません。</exception>
    public void Start()
    {
      if ( QueryPerformanceCounter(ref this._StratTime) == 0 )
      {
        throw new NotSupportedException("このシステムでは対応していません。");
      }
    }
    #endregion
    #region public void End()
    /// <summary>
    /// 計測を終了します
    /// </summary>
    /// <exception cref="NotSupportedException">このシステムではQueryPerformanceCounterが対応していません。</exception>
    public void End()
    {
      if ( QueryPerformanceCounter(ref this._EndTime) == 0 )
      {
        throw new NotSupportedException("このシステムでは対応していません。");
      }
    }
    #endregion
    #region public double Result
    /// <summary>
    /// 計測結果を返します
    /// </summary>
    /// <exception cref="NotSupportedException">このシステムではQueryPerformanceCounterが対応していません。</exception>
    public double Result
    {
      get
      {
        return (this._EndTime - this._StratTime) * 1.0 / this.Frequency;
      }
    }
    #endregion
  }
}

勉強会: 05/18 大阪 登録受付中

中の技術日誌
コンテンツ
わんくま同盟
わんくま同盟
わんくま同盟
広告
バナー
MVP LOGO
MSMVP Visual C# Since 2004/04-2007/03
MCP LOGO
070-316
姉妹サイト
姉妹サイト:じゃんぬのC#, VB.NET 入門
じゃんぬの
C#, VB.NET 入門
検索
Google

ブログ本家
広告