Conris.Utility/CodeTimer.cs

(开头部分) 5KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

//采用接口
//public class TestSleep3000 : IAction
//{
//    #region IAction Members

//    public void Action()
//    {
//        Thread.Sleep(3000);
//    }

//    #endregion
//}

//CodeTimer.Time("Thread Sleep", 1, new TestSleep3000());

//采用委托
//CodeTimer.Time("Thread Sleep", 1, delegate() { Thread.Sleep(3000); });

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Threading;
using System.Runtime.InteropServices;

namespace Conris.Utility
{
   public interface IAction
    {
        void Action();
    }

   public static class CodeTimer
   {
       [DllImport("kernel32.dll", SetLastError = true)]
       static extern bool GetThreadTimes(IntPtr hThread, out long lpCreationTime,
          out long lpExitTime, out long lpKernelTime, out long lpUserTime);

       [DllImport("kernel32.dll")]
       static extern IntPtr GetCurrentThread();

       public delegate void ActionDelegate();

       private static long GetCurrentThreadTimes()
       {
           long l;
           long kernelTime, userTimer;
           GetThreadTimes(GetCurrentThread(), out l, out l, out kernelTime,
              out userTimer);
           return kernelTime + userTimer;
       }

       static CodeTimer()
       {
           Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
           Thread.CurrentThread.Priority = ThreadPriority.Highest;

       }

       public static void Time(string name, int iteration, ActionDelegate action)
后面还有 118 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。