Algorithm - CPU Usage Curve (C++)

Algorithm 同时被 2 个专栏收录
38 篇文章 0 订阅
17 篇文章 2 订阅

分享一个大牛的人工智能教程。零基础!通俗易懂!风趣幽默!希望你也加入到人工智能的队伍中来!请点击http://www.captainbed.net

/*
 * CpuUsageCurve.h - by FreeMan
 */

#include "Windows.h"
#include "math.h"
#include "stdlib.h"

const double SPLIT = 0.01;
const int COUNT = 200;
const double PI = 3.14159265;
const int INTERVAL = 300;

int main(int argc, TCHAR *argv[])
{
    SetThreadAffinityMask(GetCurrentThread(), 1);
    DWORD busySpan[COUNT];  // Array of busy times
    DWORD idleSpan[COUNT];  // Array of idle times
    int half = INTERVAL / 2;
    double radian = 0.0;
    for (int i = 0; i < COUNT; i++)
    {
        busySpan[i] = (DWORD)(half + (sin(radian * PI) * half));
        idleSpan[i] = INTERVAL - busySpan[i];
        radian += SPLIT;
    }
    DWORD startTime = 0;
    int j = 0;
    while (true)
    {
        j = j % COUNT;
        startTime = GetTickCount64();
        while ((GetTickCount64() - startTime) <= busySpan[j])
            ;
        Sleep(idleSpan[j]);
        j++;
    }
    return 0;
}

  • 1
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

相关推荐
©️2020 CSDN 皮肤主题: 书香水墨 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值