zoukankan      html  css  js  c++  java
  • 编程之美第一题,参考某同事的算法和文章

                Process p = Process.GetCurrentProcess();

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

                
    double[] busySpan = new double[COUNT];  //array of busy times
                double[] idleSpan = new double[COUNT];  //array of idle times
                int half = INTERVAL / 2;

                
    double radian = 0.0;
                
    for (int i = 0; i < COUNT; i++)
                {
                    busySpan[i] 
    = (double)(half + (Math.Sin(PI * radian) * half));
                    idleSpan[i] 
    = INTERVAL - busySpan[i];
                    radian 
    += SPLIT;
                }

                
    double startTime = 0;
                
    int j = 0;

                
    while (true)
                {
                    j 
    = j % COUNT;

                    startTime 
    = Environment.TickCount;

                    p.ProcessorAffinity 
    = (IntPtr)0x0001;
                    
    while ((Environment.TickCount - startTime) <= busySpan[j]) ;

                    p.ProcessorAffinity 
    = (IntPtr)0x0002;
                    
    while ((Environment.TickCount - startTime) <= idleSpan[j]) ;

                    j
    ++;
                }
  • 相关阅读:
    用ElasticSearch和Protovis实现数据可视化
    分布式搜索elasticsearch配置文件详解
    PHP ElasticSearch的使用
    在Windows .NET平台下使用Memcached
    升級 Centos 6.5 的 php 版本
    elasticsearch-查询基础篇
    Elasticsearch 权威指南
    [转] Mongoose初使用总结
    [转] 深入浅出mongoose-----包括mongoose基本所有操作,非常实用!!!!!
    [转] mongodb下载、安装、配置与使用
  • 原文地址:https://www.cnblogs.com/Jax/p/1695295.html
Copyright © 2011-2022 走看看