zoukankan      html  css  js  c++  java
  • 任意調整CUP成直綫

            //任意調整CUP直綫
            static void getUsage(float level)
            {
                PerformanceCounter p = new PerformanceCounter("Processor", "% Processor Time", "_Total");  
                if (p == null)
                {
                    return;
                }

                while (true)
                {
                    if (p.NextValue() > level)
                    {
                        System.Threading.Thread.Sleep(20);
                    }
                }

            }

     PS.程序在本機測試顯示50%。

            /// <summary>
            ///
            /// </summary>
            /// <param name="cupHz">cup HZ,如:2.53</param>
            /// <param name="ratio">cup 占用百分比,如:0.8</param>
            static void getUsage_1(float cupHz, float ratio)
            {
                double r = (1 - ratio) * 10;
                double hz = (cupHz * Math.Pow(10d, 9d) * 2) / r;
                for (; ; )
                {
                    for (int i = 0; i < hz / 1000; i++)
                    {

                    }

                    System.Threading.Thread.Sleep(15);
                }
            }
    PS.  對0.5(50%)以上較准.  需知道本地CUP工作頻率.
     

  • 相关阅读:
    模糊查询的like '%$name$%'的sql注入避免
    在VS2010中使用Git(转)
    android WebView解析 调用html5
    git
    推荐!手把手教你使用Git
    羽毛拍十大品牌
    乒乓球拍板和皮子世界排名
    足球小记
    centos 网络启动 在/etc/sysconfig/network-scripts/ifcfg-eth1onboot=yes即可
    MyEclipseGen--------生成
  • 原文地址:https://www.cnblogs.com/wang123/p/1372821.html
Copyright © 2011-2022 走看看