CPU Sin

16900 단어 c일 하 다iostream
1 #include <iostream>
 2 #include <cmath>
 3 #include <ctime>
 4 #include <windows.h>
 5 
 6 using namespace std;
 7 
 8 //    0xFFFFFFFF     
 9 unsigned int test()
10 {
11     unsigned int c = 0xFFFFFFFF;
12 
13     time_t t1, t2;
14     time(&t1);
15 
16     for(unsigned int i = 0; i < c; i++)
17         ;
18     time(&t2);
19     return (unsigned int)(t2 -t1);
20 
21 }
22 
23 
24 #define T  20000                                        //     20 
25 #define C  100                                            //       
26 #define PI 3.1415                                        //PI
27 const unsigned int count = 0xFFFFFFFF / (test() *1000); //           
28 const unsigned int N = T/C;                                //        
29 unsigned int v[N] = { 0 };                                //            
30 unsigned int mt[N] = { 0 };                                //          
31 
32 int main()
33 {
34     //           
35     for(int i = 0; i < N; i++)
36     {
37         double x = (2 * PI / N)* i ;//2*PI/N   2PI x    N ,  i   i     sin      
38         double r = (sin(x) + 1) / 2;// sine     [0,1],as a coefficient,      C        (y 0-100%)
39         
40         mt[i] = C - r * C;//(1-r)C,     C      ,    C     r*c,   (1-r)*C,      。   C     ,y  sin           
                                   //rate = work/C  ->  rate = r ->  work = r*c  
41         v[i] = r * C * count;//r*C     C      , *count,       for 
42     }
43     for(;;)
44     {
45         for(int i = 0; i < N; i++)
46         {
47             for(int j = 0; j < v[i]; j++)
48                 ;
49             Sleep(mt[i]);
50         }
51     }
52 }

좋은 웹페이지 즐겨찾기