performence timer

    1. public   class T_DebugPerformanceCounter  
    2.     {  
    3.         [System.Runtime.InteropServices.DllImport("Kernel32.dll")]  
    4.         static extern bool QueryPerformanceCounter(ref long count);  
    5.   
    6.         [System.Runtime.InteropServices.DllImport("Kernel32.dll")]  
    7.         static extern bool QueryPerformanceFrequency(ref long count);  
    8.   
    9.         public static T_DebugPerformanceCounter FactoryTimer()  
    10.         {  
    11.             if (_MeTimer == null)  
    12.             {  
    13.                 _MeTimer = new T_DebugPerformanceCounter();  
    14.             }  
    15.             return _MeTimer;  
    16.         }  
    17.   
    18.         //==================================================================  
    19.         private static long _Frequency;  
    20.         private   long _StartCount;  
    21.         private T_DebugPerformanceCounter()  
    22.         {  
    23.             QueryPerformanceFrequency(ref _Frequency);  
    24.               
    25.         }  
    26.         private static T_DebugPerformanceCounter _MeTimer;  
    27.         public void StartCount()  
    28.         {  
    29.             QueryPerformanceCounter(ref _StartCount);  
    30.         }  
    31.   
    32.         public void PerformCount(string info)  
    33.         {  
    34.             long count1 = 0;  
    35.             double result = 0;                
    36.   
    37.             QueryPerformanceCounter(ref count1);  
    38.             long p = count1 - _StartCount;  
    39.             result = (double)(p) / (double)_Frequency*1000;  
    40.             UtiltyObj.WriteExceptionToLog(string.Format(info + "耗时: {0} 毫  秒", result), System.Diagnostics.EventLogEntryType.SuccessAudit , EventLevel.运行 );  
    41.         }          
    42.     } 

posted on 2012-11-07 10:35  CDiamond  阅读(169)  评论(0编辑  收藏  举报

导航