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工作頻率.
     

  • 相关阅读:
    linux使用windows中编辑的文件,格式问题
    模拟退火算法c++
    progress第三方框架和二维码第三方框架的选择
    iOS 初始化项目内容
    github上使用SSH和gitignore
    wordpress 如何设置自定义的首页
    wordpress 删除底部"自豪地采用 WordPress"
    masonry注意事项
    iOS修改工程名
    iOS版本更新在APP中直接访问AppStore
  • 原文地址:https://www.cnblogs.com/wang123/p/1372821.html
Copyright © 2011-2022 走看看