publicclassPerformanceHelperClass{[DllImport("Kernel32.dll")]publicstaticexternvoidQueryPerformanceCounter(reflongticks);[DllImport("Kernel32.dll")]publicstaticexternvoidQueryPerformanceFrequency(reflongfreq);publicstaticlongGetCurrentTick(){longvalue=0;QueryPerformanceCounter(refvalue);returnvalue;}publicstaticlongGetPerformanceFrequency(){longvalue=0;QueryPerformanceFrequency(refvalue);returnvalue;}}publicclassPerformanceCouterable{protectedlongm_tickCreated;protecteddoublem_frequency;publicPerformanceCouterable(){ResetStartPerformanceTick();}protectedvoidResetStartPerformanceTick(){m_frequency=((double)PerformanceHelperClass.GetPerformanceFrequency())/1000.0;m_tickCreated=PerformanceHelperClass.GetCurrentTick();}protectedlongGetPerformanceElapsedTick(){returnPerformanceHelperClass.GetCurrentTick()-m_tickCreated;}protecteddoubleGetElapsedTime(){varelapsed=PerformanceHelperClass.GetCurrentTick()-m_tickCreated;return(double)elapsed/m_frequency;}}publicclassMesaureScope:PerformanceCouterable,IDisposable{privatestringm_scopeName=string.Empty;publicMesaureScope(stringname){m_scopeName=name;Trace.WriteLine(string.Format("[MEASURE TIME - BEGIN] {0}",m_scopeName));}publicvoidDispose(){Trace.WriteLine(string.Format("[MEASURE TIME - END ] {0} - {1}(ms)",m_scopeName,GetElapsedTime()));}}